Skip to content

Instantly share code, notes, and snippets.

View tjmehta's full-sized avatar
💭
🌉

Tejesh Mehta tjmehta

💭
🌉
View GitHub Profile
@tjmehta
tjmehta / isHex.js
Last active August 31, 2022 05:51
Function that checks if a number is Hex with Javascript (ES5)
var compose = function() {
var funcs = Array.prototype.slice.apply(arguments);
return function(arg) {
return funcs.reduce(function(arg, fn) {
return fn.call(this, arg);
}, arg);
};
};
var and = function() {
@tjmehta
tjmehta / cookie.js
Created December 11, 2012 00:27
Cookie parser snippet
@tjmehta
tjmehta / LastArg.js
Created November 24, 2012 16:24
Last arg function
var fn = function(one, two, three, callback) {
var args = Array.prototype.slice.apply(arguments);
var lastArg = args.pop()
if (callback !== lastArg && typeof lastArg == 'function') {
callback = lastArg;
arguments[args.length] = undefined; // not -1 bc of pop above
}
// Handle undefined values, by setting default value
// .. Rest of function ..
}
//
// in AppDelegate
//
// Initialize RestKit Shared Client
RKObjectManager *objectManager = [RKObjectManager objectManagerWithBaseURLString:_baseURL];
// Enable automatic network activity indicator management
objectManager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;
// Initialize object store
class Bunch(dict):
def __init__(self, *args, **kwds):
super(Bunch, self).__init__(*args, **kwds)
self.__dict__ = self
@tjmehta
tjmehta / nginx.conf
Created April 18, 2012 19:51
nginx conf
server {
listen 80;
server_name localhost;
root /swelly/static;
location / {
try_files index.html =404;
}
location /api {
proxy_pass http://127.0.0.1:3000/api;
}
@tjmehta
tjmehta / TheElevatorHack.js
Created February 2, 2012 21:55
The Elevator Game Hack
(function clickIt() {
var $form = $("form"); //the only form on the page is the elevator button of interest.
var postURL = $form.attr("action"); //post url of the form
var postData = {};
var inputs = $("input", $form);
for (var i = inputs.length; i--;) {
// serialize the form elements into an object
postData[inputs.eq(i).attr("name")] = inputs.eq(i).val();
}
//clicking the elevator button of interest was submitting a form contained w/in it