Skip to content

Instantly share code, notes, and snippets.

View whitfin's full-sized avatar
🏠
Working from home

Isaac Whitfield whitfin

🏠
Working from home
View GitHub Profile
@ericeijkelenboom
ericeijkelenboom / emr_bootstrap_java_8.sh
Created April 3, 2014 09:39
Bootstrap script for installing Java 8 on an Amazon Elastic MapReduce instance (AMI 3.0.1)
# Check java version
JAVA_VER=$(java -version 2>&1 | sed 's/java version "\(.*\)\.\(.*\)\..*"/\1\2/; 1q')
if [ "$JAVA_VER" -lt 18 ]
then
# Download jdk 8
echo "Downloading and installing jdk 8"
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8-b132/jdk-8-linux-x64.rpm"
# Silent install
@bly2k
bly2k / gist:9843335
Created March 28, 2014 21:26
Elasticsearch value_count and cardinality
curl -XDELETE localhost:9200/test
curl -XPUT localhost:9200/test/doc/1 -d '{ "a": "1" }'
curl -XPUT localhost:9200/test/doc/2 -d '{ "a": "1" }'
curl -XPUT localhost:9200/test/doc/3 -d '{ "a": "1" }'
curl -XPOST "localhost:9200/test/_search?search_type=count&pretty" -d '{
"aggs": {
@robertoaloi
robertoaloi / kill-erlang-node.sh
Created February 8, 2014 13:55
Kill an Erlang process by node name
#!/usr/bin/env bash
# Kill an Erlang process by node name
#
# e.g.: kill-erlang-node kred
# Check usage
if [ -z "$1" ]; then
echo "Usage: `basename $0` NODE_NAME"
exit 1
@tkh44
tkh44 / FileController.js
Last active March 10, 2020 09:04
Simple file upload for sails.js
module.exports = {
get: function (req, res) {
res.sendfile(req.path.substr(1));
},
_config: {
rest: false,
shortcuts: false
}
};
@branneman
branneman / better-nodejs-require-paths.md
Last active April 27, 2024 04:16
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@nghuuphuoc
nghuuphuoc / 1) Install
Last active September 4, 2023 09:29
Install Redis on Centos 6
// --- Compiling ---
$ wget http://download.redis.io/releases/redis-2.8.3.tar.gz
$ tar xzvf redis-2.8.3.tar.gz
$ cd redis-2.8.3
$ make
$ make install
// --- or using yum ---
$ rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
$ rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
@nternetinspired
nternetinspired / gist:7482445
Last active February 24, 2022 17:20
Load Disqus comments only on demand if you give a shit about page weight and your visitors. Even with no comments, i.e. an empty comment form, calling Disqus will load an extra 226Kb. If your page has comments this can be far higher. This Gist accompanies my blog post: http://internet-inspired.com/wrote/load-disqus-on-demand/
// Requires jQuery of course.
$(document).ready(function() {
$('.show-comments').on('click', function(){
var disqus_shortname = 'YOUR-DISQUS-USERNAME'; // Replace this value with *your* username.
// ajax request to load the disqus javascript
$.ajax({
type: "GET",
url: "http://" + disqus_shortname + ".disqus.com/embed.js",
dataType: "script",
@Tasssadar
Tasssadar / flo.xml
Created October 11, 2013 11:43
Manifest for flo, for B2G build
<?xml version="1.0" ?><manifest>
<include name="base-jb.xml"/>
<remote fetch="git://github.com/Tasssadar/" name="tasssadar"/>
<default remote="caf" revision="refs/tags/android-4.3_r2.1" sync-j="4"/>
<!-- flo specific things -->
<project name="android_device_asus_flo" path="device/asus/flo" remote="tasssadar" revision="b2g-4.3_r2.1" />
<project name="device/generic/armv7-a-neon" path="device/generic/armv7-a-neon"/>
@joelittlejohn
joelittlejohn / TtlHashMap.java
Last active October 4, 2023 10:50
A passive TTL hash map, that expires and removes values if they are older than some time-to-live. I have only proved it correct, not tried it ;) [As the author of this code, I dedicate it to the public domain https://creativecommons.org/publicdomain/zero/1.0]
package com.example;
import static java.util.Collections.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@steve-taylor
steve-taylor / doSynchronousLoop.js
Last active December 4, 2022 00:51
Synchronous for loop in JavaScript to ensure that the n+1th item isn't processed until the callback of the nth item's processor has been called.
/**
* Process an array of data synchronously.
*
* @param data An array of data.
* @param processData A function that processes an item of data.
* Signature: function(item, i, callback), where {@code item} is the i'th item,
* {@code i} is the loop index value and {@code calback} is the
* parameterless function to call on completion of processing an item.
*/
function doSynchronousLoop(data, processData, done) {