Skip to content

Instantly share code, notes, and snippets.

View muhammadghazali's full-sized avatar

Muhammad Ghazali muhammadghazali

View GitHub Profile
@muhammadghazali
muhammadghazali / TimestampUtils.java
Created January 28, 2016 06:06 — forked from kristopherjohnson/TimestampUtils.java
Methods for generating ISO 8601 timestamps in Java/Android
package net.kristopherjohnson.util;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
/**
* Methods for dealing with timestamps
Something
.findOne({
where: {
id: somethingId
}
})
.then(function(something) {
throw new Error('something not found');
return doSomethingCool();
Something
.findOne({
where: {
id: somethingId
}
})
.then(function(something) {
if (!something) {
res.notFound('Something is not found.');
return;
@muhammadghazali
muhammadghazali / index.js
Last active October 17, 2015 07:47
requirebin sketch
moment = function() {
return (require('moment-timezone')).tz('America/New_York');
},
console.log(moment().format());
console.log(moment().day());
console.log(moment().endOf('day').format());
console.log(moment().endOf('day').format());
@muhammadghazali
muhammadghazali / testrunner.html
Last active September 4, 2015 18:51 — forked from jonnyreeves/testrunner.html
Unit Testing Promises with Sinon.js
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css" type="text/css" media="screen" />
<!-- when.js Promises implementation -->
<script src="https://raw.github.com/cujojs/when/master/when.js"></script>
<!-- Unit testing and mocking framework -->
<script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js"></script>
// To disable socket.io, disable the sockets hook (you'll have to disable the pubsub hook as well)
// This is a replacement for the default app.js file:
require('sails').lift({
hooks: {
sockets: false,
pubsub: false
}
@muhammadghazali
muhammadghazali / index.js
Created June 2, 2015 14:35
requirebin sketch
var moment = require('moment');
var today = moment().startOf('day');
console.log("today ", moment().startOf('day'));
console.log("tomorrow ", moment(today).add(1, 'days'));
var day = moment().unix() * 1000;
var dayInISO = moment().millisecond(moment().unix());
console.log(dayInISO.format());
console.log("Today in ISO ", moment().format());
console.log("Today ", moment());
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@muhammadghazali
muhammadghazali / ignore all the files inside upload directory.md
Created September 20, 2014 16:54
ignore all the files inside upload directory
# we ignore all the files inside upload directory
/*
# then we only include the following files, the rest of the files will be ignored
!.gitignore
!.gitkeep