Skip to content

Instantly share code, notes, and snippets.

View TheDeveloper's full-sized avatar

TheDeveloper TheDeveloper

View GitHub Profile
@TheDeveloper
TheDeveloper / inString.js
Created July 21, 2012 11:19
Check for string in another string
var inString = ~string.indexOf('search') ? 'yep!' : 'nope';
@TheDeveloper
TheDeveloper / createHash.js
Created July 21, 2012 11:20
Create a hash in node.js
var crypto = require('crypto');
var createHash = function(algo, data, digest){
if(!digest)
digest = 'hex';
return crypto.createHash(algo).update(data).digest(digest);
}
@TheDeveloper
TheDeveloper / gist:3689961
Created September 10, 2012 09:41
Change to git project root directory
cd $(git rev-parse --show-toplevel)
@TheDeveloper
TheDeveloper / gist:4512889
Created January 11, 2013 18:33
Lua script for use in redis. Deletes all keys matching argument 1. Returns count for total number of keys deleted.
local keys
keys = redis.call('keys', KEYS[1])
local ret=0
local type
for k,v in pairs(keys) do
redis.call('del', v)
ret = ret+1
end
return ret
# View list of connections and their states
netstat -tan | grep ':80 ' | awk '{print $6}' | sort | uniq -c
# List all connections and timers
ss -rota | less
@TheDeveloper
TheDeveloper / gist:5404654
Created April 17, 2013 14:18
Usage: remove_submodule submodule_path Where submodule_path is the relative path to your submodule from the current directory. Must be run from the root of a git working copy
# Sweep a git submodule out of the working copy
remove_submodule() {
SMD_PATH=$1
if [ ! -d $SMD_PATH ]; then
echo "$SMD_PATH does not exist"
return 1
fi
git config -f .git/config --remove-section submodule.$SMD_PATH
git config -f .gitmodules --remove-section submodule.$SMD_PATH
@TheDeveloper
TheDeveloper / lock.lua
Created March 17, 2014 16:33
Set a lock in Redis
--
-- Set a lock
--
-- KEYS[1] - key
-- KEYS[2] - ttl in ms
-- KEYS[3] - lock content
local key = KEYS[1]
local ttl = KEYS[2]
local content = KEYS[3]
@TheDeveloper
TheDeveloper / http-aws-es.es6.js
Last active March 31, 2021 09:27
Use the Node elasticsearch client with Amazon ES
/**
* A Connection handler for Amazon ES.
*
* Uses the aws-sdk to make signed requests to an Amazon ES endpoint.
* Define the Amazon ES config and the connection handler
* in the client configuration:
*
* var es = require('elasticsearch').Client({
* hosts: 'https://amazon-es-host.us-east-1.es.amazonaws.com',
* connectionClass: require('http-aws-es'),
/**
* A Connection handler for Amazon ES.
*
* Uses the aws-sdk to make signed requests to an Amazon ES endpoint.
* Define the Amazon ES config and the connection handler
* in the client configuration:
*
* var es = require('elasticsearch').Client({
* hosts: 'https://amazon-es-host.us-east-1.es.amazonaws.com',
* connectionClass: require('http-aws-es'),
@TheDeveloper
TheDeveloper / es-migrate.es6.js
Last active February 15, 2022 01:36
Script to migrate documents from one Elasticsearch cluster to another using Scan/Scroll
/*
Migrate documents from one elasticsearch endpoint to another.
To squeeze out extra performance, disable index refresh and replicas on the target cluster:
curl -XPUT 'http://elasticsearch:9200/_settings' -d '{
"index" : {
"refresh_interval" : "-1",
"number_of_replicas": "0"
}