Skip to content

Instantly share code, notes, and snippets.

View virasak's full-sized avatar

Virasak Dungsrikaew virasak

View GitHub Profile
@virasak
virasak / 0_reuse_code.js
Created August 16, 2014 05:41
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@virasak
virasak / tailrec.js
Last active August 29, 2015 14:01
Tail Call Optimization for JS
module.exports = function tailrec(f) {
var args = null;
return function () {
if (args) return (args = arguments);
var result = (args = arguments);
while (result === args) result = f.apply(this, args);
args = null;
return result;
};
};
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
#!/bin/bash
# node.js using PPA (for statsd)
sudo apt-get install python-software-properties
sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm
# Install git to get statsd
sudo apt-get install git
@virasak
virasak / docserver.php
Created April 15, 2013 14:17
Serve AngularJS documents directly from distributed zip file with PHP 5.4 built-in web server.
<?php
// To run this script:
// php localhost:8080 docserver.php
$dirname = 'angular-1.0.6'; // without '.zip'
$uri = $_SERVER['REQUEST_URI'];
if (in_array($uri, array('/', '/docs', '/docs/'))) {
header('Location: /docs/index.html', 302);
} else {
@virasak
virasak / docserver.js
Last active May 2, 2022 03:50
AngularJS Offline Document Server with NodeJS. Serve AngularJS documents from the distributed zip file without extraction. Windows user may find this script useful, because the documents contain illegal file names for Windows. This script requires `mime` and `adm-zip` packages.
if (process.argv.length < 3) {
console.log('Usage: node docserver.js angular-x.y.z.zip [port]');
return;
}
var zipfile = process.argv[2],
port = Number(process.argv[3]) || 1337,
path = require('path'),
dirname = path.basename(zipfile, '.zip'),
http = require('http'),
@virasak
virasak / JSONClient.php
Created April 9, 2013 15:58
Simple JSON Client with cURL in PHP
<?php
class JSONClient {
private $opt_array = array(
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => array('Content-type: application/json'));
private $last_error = NULL;
public function __construct($opt = array()) {
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00
package testme;
import com.google.inject.ImplementedBy;
@ImplementedBy(AuthenFacadeImpl.class)
public interface AuthenFacade {
boolean login();
}
@virasak
virasak / AuthenService.java
Created September 28, 2012 06:09
Simple Guice & JUnit4 Integration: Use the unit test itself as a module to provide member injection. Use @provides methods to build a module from unit test object.
import com.google.inject.Inject;
public class AuthenService {
private final UserDAO userDAO;
@Inject
public AuthenService(UserDAO userDAO) {
this.userDAO = userDAO;