Skip to content

Instantly share code, notes, and snippets.

View tjmehta's full-sized avatar
💭
🌉

Tejesh Mehta tjmehta

💭
🌉
View GitHub Profile
@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
@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;
}
class Bunch(dict):
def __init__(self, *args, **kwds):
super(Bunch, self).__init__(*args, **kwds)
self.__dict__ = self
//
// 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
@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 ..
}
@tjmehta
tjmehta / cookie.js
Created December 11, 2012 00:27
Cookie parser snippet
@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 / javascript-object-to-querystring.js
Last active January 28, 2024 22:35
Object to Querystring - JavaScript, JS, JSON
function objectToQuerystring (obj) {
return Object.keys.reduce(function (str, key, i) {
var delimiter, val;
delimiter = (i === 0) ? '?' : '&';
key = encodeURIComponent(key);
val = encodeURIComponent(obj[key]);
return [str, delimiter, key, '=', val].join('');
}, '');
}
ERROR: apport (pid 23850) Tue Sep 1 21:07:32 2015: Unhandled exception:
Traceback (most recent call last):
File "/usr/share/apport/apport", line 54, in drop_privileges
stat = os.stat('/proc/' + pid)
FileNotFoundError: [Errno 2] No such file or directory: '/proc/43'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/share/apport/apport", line 276, in <module>
#!/usr/bin/python3
# Collect information about a crash and create a report in the directory
# specified by apport.fileutils.report_dir.
# See https://wiki.ubuntu.com/Apport for details.
#
# Copyright (c) 2006 - 2011 Canonical Ltd.
# Author: Martin Pitt <martin.pitt@ubuntu.com>
#
# This program is free software; you can redistribute it and/or modify it