Skip to content

Instantly share code, notes, and snippets.

View allenhwkim's full-sized avatar

Allen Kim allenhwkim

View GitHub Profile
@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
))
@allenhwkim
allenhwkim / websocket_client.rb
Created April 18, 2012 21:31
Ruby websocket client
#
# This is modified version of https://github.com/gimite/web-socket-ruby/blob/master/lib/web_socket.rb
#
# Lincense: New BSD Lincense
#
require "base64"
require "socket"
require "uri"
require "digest/md5"
~/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;
}
@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:be508558869f322e7697
Created October 22, 2014 14:48
Angular Google Maps Fit Bounds
<!doctype html>
<html ng-app="myapp">
<head>
<script src="https://maps.googleapis.com/maps/api/js"></script>
<script src="http://code.angularjs.org/1.2.25/angular.js"></script>
<script src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>
<script>
var app = angular.module('myapp', ['ngMap']);
app.controller('MyCtrl', function($scope) {
$scope.positions = [ [-24,132] ,[-25,131] ,[-26,130] ];
@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 {