Skip to content

Instantly share code, notes, and snippets.

View tjmehta's full-sized avatar
💭
🌉

Tejesh Mehta tjmehta

💭
🌉
View GitHub Profile
@tjmehta
tjmehta / dataview-polyfill.js
Created April 5, 2016 00:05
DataView (and ArrayBuffer) polyfill that works in any engine (including old IE).
void function(global){
if ('DataView' in global && 'ArrayBuffer' in global) {
return;
}
var hide = (function(){
// check if we're in ES5
if (typeof Object.getOwnPropertyNames === 'function' && !('prototype' in Object.getOwnPropertyNames)) {
var hidden = { enumerable: false };
@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 / 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('');
}, '');
}
foreign foreign foreign [Applause] thank you the committee will come to order without objection the chair is authorized to declare a recess of the committee at any time this hearing is entitled the annual testimony of the Secretary of the Treasury on the state of the International Financial system without objection all members will have five legislative days within which to submit extraneous materials to the chair for inclusion in the record I will note if the outside of this hearing that we have a hard stop as a courtesy to the secretary at 1 pm this afternoon we will strictly observe it now I'll recognize myself for four minutes to give an opening statement welcome secretary Yellen I appreciate you being here today today's hearing is about the state of the international financial institutions but I do want to take a minute and talk about the debt ceiling crisis that we narrowly avoided first we're all glad that this is behind us no one wanted default no legislative branch official no executive branch offici
@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() {

Keybase proof

I hereby claim:

  • I am tjmehta on github.
  • I am tjmehta (https://keybase.io/tjmehta) on keybase.
  • I have a public key ASBdiqNrVKvhZkXTt76rhWnhh1KbIDrW0kM3WCtI0nSWSAo

To claim this, I am signing this object:

@tjmehta
tjmehta / redis-expire.sh
Created July 8, 2018 05:57 — forked from fieg/redis-expire.sh
Set expire on large set of keys using pattern in Redis
#!/bin/bash
if [ $# -ne 4 ]
then
echo "Usage: $0 <host> <port> <pattern> <seconds>"
exit 1
fi
cursor=-1
keys=""
{
//...
// plugins
plugins: [
'karma-*',
{
'middleware:custom': ['factory', function (config) {
return function (req, res, next) {
console.log('HELLO!')
res.end('hello-world')
@tjmehta
tjmehta / publish-static.js
Created February 9, 2016 23:09
Publish all expose ports to 1-to-1 w/ docker host
#!/usr/bin/env node
# Usage: docker run [..opts] `publish-static <image>:<tag>`
'use strict'
const execSync = require('child_process').execSync
const image = process.argv[2]
const inspect = JSON.parse(
execSync('docker inspect ' + image).toString()
@tjmehta
tjmehta / cookie.js
Created December 11, 2012 00:27
Cookie parser snippet