Posts

Quick start with Express JS

Image
Your first step to Express JS development Prerequisites software Node JS Guide Install express by  npm install express --save Install express-generator by  npm install -g express-generator Create project using  express <Project Name> To install all dependencies required by Express JS to start  npm install To start the server: npm start To test your example: Type the following address in your browser: http://localhost:3000/ You will see the following screen. CONGRATULATIONS, your first Express JS web app has been created successfully

GIT - Add repository to folder which have content

Hi all, its been sometime since I updated my blog.  This time I encounter some issue with git. I start my project before I creating the repository ( which should be the other way round ). After several search from internet and do some try and error, I figure out it is quite simple. Start your Git Bash application and do the following: # cd <code location> # git init # git add . # git commit -m "my message" # git remote add origin <git url> # git push -u origin master TADA! And your folder now is link with your git repository. So what the above did? 1. git init : Initialize the folder as git directory 2. git add . : Add all files within the folder, including subfolders and their files 3. git commit -m "my message" : Commit the staged code and give a comment of the commit as "My Message" 4. git remote add origin <git url> : Add the git repository url as remote url 5. git push -u origin master : Push cod

Jquery Fancybox auto display upon page load

Encounter this issue where it is needed to auto pop up Jquery Fancybox item. The solution is very easy. $(document).ready(function(){     $('#myElementId').fancybox().trigger('click'); }); Summary: The main point here this snippet of code: .trigger('click'); which will auto pop up fancybox

Multiple ngApp in 1 page or 1 application

I encounter this issue where there are 2 applications which is totally handled by different ngApp but they want to put them as a same application. After a quick search online, found that actually we can bootstrap the page with different ngApp manually instead of by defining ngApp at body tag. See below sample source for example HTML <!doctype html> <html>     <head>         <meta charset="utf-8">         <title>AngularJS Plunker</title>         <script>document.write('<base href="' + document.location + '" />');</script>         <link rel="stylesheet" href="style.css">          </head>     <body ng-app="HelloWorldApp">         Test 1         <section id="helloworld" ng-controller="HelloWorldController">             Hello {{name}}!         </section>          <br />         <

Setting Apache HTTP server upload limit

Today encounter an issue to upload image and then saw the below exception stack: Caused by: org.apache.commons.fileupload.FileUploadException at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:385) [commons-fileupload-1.2.2.jar:1.2.2] at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126) [commons-fileupload-1.2.2.jar:1.2.2] at org.springframework.web.multipart.commons.CommonsMultipartResolver.parseRequest(CommonsMultipartResolver.java:156) [spring-web-3.2.12.RELEASE.jar:3.2.12.RELEASE] ... 88 more Caused by: ClientAbortException:  java.io.IOException: Socket read failed at org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:357) [jbossweb-7.0.13.Final.jar:] at org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:420) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:379) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.con

Django Form: Adding html text to help_text in FormField or ModelField

Today I come across the requirement to have a link inside the help_text for ModelField. Hence I found this simple and fast solution and would like to share with you all. Before: my_field = models.CharField(max_length=10, help_text='Simple help text here') Solution: from django.utils.safestring import mark_safe my_field = models.CharField(max_length=10, help_text= mark_safe ('Simple help text here. <p>HTML code here</p>')) That's it and your help text will have this html code in place. Happy Coding!

DJango Queryset comparing date time

Good day to all developers. Today encountered this issue where I do a simple queryset in DJango and hit with the following warning message:   RuntimeWarning: DateTimeField MessageContent.send_time received a naive datetime (2014-05-14 04:46:30.392000) while time zone support is active. How is this happen? This is due to I do the following datetime comparison in my queryset: import datetime Item.objects.filter(created = datetime.datetime.now()) The error is due to TIME_ZONE (in settings.py) is enabled by default. So the solution for this is pretty simple: 1) Either to set the TIME_ZONE to False in settings.py ( this will take away the timezone capability of your application) 2) or by comparing to timezone enabled datetime which the code as below: import datetime from django.utils.timezone import utc now = datetime.datetime.utcnow().replace(tzinfo=utc) Item.objects.filter(created = now) With this, the problem has been solved. More information c