Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
🌉

Tejesh Mehta tjmehta

💭
🌉
View GitHub Profile
View keybase.md

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 Jul 8, 2018 — forked from fieg/redis-expire.sh
Set expire on large set of keys using pattern in Redis
View redis-expire.sh
#!/bin/bash
if [ $# -ne 4 ]
then
echo "Usage: $0 <host> <port> <pattern> <seconds>"
exit 1
fi
cursor=-1
keys=""
@tjmehta
tjmehta / dataview-polyfill.js
Created Apr 5, 2016
DataView (and ArrayBuffer) polyfill that works in any engine (including old IE).
View dataview-polyfill.js
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 };
View karma.conf.js
{
//...
// 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 Feb 9, 2016
Publish all expose ports to 1-to-1 w/ docker host
View publish-static.js
#!/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 / domains-emitter-example.js
Last active Oct 12, 2015
Unexpected domain error handling
View domains-emitter-example.js
var Domain = require('domain')
var d1 = Domain.create();
var emitter;
d1.on('error', handleCreateErr)
d1.run(function () {
emitter = createEmitter()
})
var d2 = Domain.create();
View apport.py
#!/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
View apport.log
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>
@tjmehta
tjmehta / javascript-object-to-querystring.js
Last active Nov 14, 2020
Object to Querystring - JavaScript, JS, JSON
View javascript-object-to-querystring.js
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('');
}, '');
}
@tjmehta
tjmehta / isHex.js
Last active Aug 7, 2020
Function that checks if a number is Hex with Javascript (ES5)
View isHex.js
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() {