Skip to content

Instantly share code, notes, and snippets.

View allenhwkim's full-sized avatar

Allen Kim allenhwkim

View GitHub Profile
@allenhwkim
allenhwkim / authentications.js
Last active August 29, 2015 14:05
Server-side angularjs-auth implementation
/***********************
* authentications.js
************************/
var jwt = require('jwt-simple');
var crypto = require('crypto');
var secret = process.env.TOKEN_SECRET || 'shhhhhhhhhh';
var authHeaderName = "x-access-token";
var md5Username = '21232f297a57a5a743894a0e4a801fc3';
var md5Password = '9d51b3f14e6d6763bd11fd73cf470bf2';
var md5 = function(str) {
@allenhwkim
allenhwkim / gist:280f271078148f69c4b6
Created February 9, 2015 22:49
Server Status Check Bash Script
!/bin/bash
i=0; array=();
array[(i++)]="-X POST http://my.server.com:3000/path"
array[(i++)]="-X GET http://my.server.com:4000"
for LINE in "${array[@]}"
do
curl -o /dev/null --silent --head -m 1 --write-out '%{http_code}' $LINE
echo " $LINE"
@allenhwkim
allenhwkim / gist:5c1a6ebe7628de1582df
Created April 26, 2015 14:27
Javascript To set see scope easily in console with CTRL-click
document.addEventListener('contextmenu', function(evt) {
if (evt.ctrlKey) {
window.$0 = evt.target;
window.s = angular.element($0).scope();
evt.preventDefault();
return false;
}
})
{
// JSHint Default Configuration File (as on JSHint website)
// See http://jshint.com/docs/ for more details
"regexp": true,
"-W065" : true, // suppress missing radix parameter warning
"-W089" : true, // suppress The body of a for in should be wrapped in an if statement
"-W030" : true, // suppress Expected an assignment or function call and instead saw an expression
"maxerr" : 50, // {int} Maximum error before stopping
<!DOCTYPE html>
<html>
<head>
<script src="angular.js"></script>
<script>
angular.module('myApp', []).
factory('datepicker', function($compile, $document){
var datepickerEl, datepickerElCtrl;
return {
@allenhwkim
allenhwkim / micro-template.js
Created August 12, 2015 14:12
micro template
'use strict';
var _cache = {};
var microTemplate = function(str, data) {
var func = _cache[str];
if (!func) {
var strFunc =
"var p=[],print=function(){p.push.apply(p,arguments);};" +
"with(obj){p.push('" +
//str.replace(/[\r\t\n]/g, " ")
@allenhwkim
allenhwkim / micro-template-test.js
Created August 12, 2015 14:13
micro template test
var microTemplate = require(__dirname + '/micro-template.js');
/*******************************************************
* `<%= %>` expression test
*******************************************************/
var layout = [
'<script type="text/html" id="item_tmpl">',
' <div id="<%=id%>" class="<%=(i % 2 == 1 ? " even" : "")%>">',
' <div class="grid_1 alpha right">',
' <img class="righted" src="<%=profile_image_url%>"/>',
@allenhwkim
allenhwkim / gist:1993750
Created March 7, 2012 15:18
fb_graph_overrides
module FbGraph
module Connections
module AdCampaigns
def ad_campaign!(options = {})
ad_campaign = post(options.merge(:connection => :adcampaigns))
fb_data = ad_campaign[:data]? ad_campaign[:data][:campaigns][ad_campaign[:id]] : ad_campaign
AdCampaign.new(ad_campaign[:id], options.merge(fb_data.symbolize_keys).merge(
:access_token => options[:access_token] || self.access_token
))
~/arcturus$irb
>> class A
>> end
=> nil
>> A.methods
=> [:allocate, :new, :superclass, :freeze, :===, :==, :<=>, :<, :<=, :>, :>=, :to_s, :included_modules, :include?, :name, :ancestors, :instance_methods, :public_instance_methods, :protected_instance_methods, :private_instance_methods, :constants, :const_get, :const_set, :const_defined?, :const_missing, :class_variables, :remove_class_variable, :class_variable_get, :class_variable_set, :class_variable_defined?, :module_exec, :class_exec, :module_eval, :class_eval, :method_defined?, :public_method_defined?, :private_method_defined?, :protected_method_defined?, :public_class_method, :private_class_method, :autoload, :autoload?, :instance_method, :public_instance_method, :nil?, :=~, :!~, :eql?, :hash, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :frozen?, :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :i
@allenhwkim
allenhwkim / gist:8071013
Created December 21, 2013 15:44
The fastest search ever for large amount of data http://jsperf.com/binary-search-1234
function search(arr, o) {
var l = 0,
u = arr.length,
m;
while (l <= u) {
if (o > arr[(m = ((l + u) >> 1))])
l = m + 1;
else
u = (o == arr[m]) ? -2 : m - 1;
}