Skip to content

Instantly share code, notes, and snippets.

View maruf89's full-sized avatar

Marius Miliunas maruf89

  • Vilnius, Lithuania
View GitHub Profile
@maruf89
maruf89 / Bind Polyfill
Created November 6, 2013 22:42
Experimenting with a polyfill for bind
Function.prototype.bind = function(obj) {
if (Function.prototype.bind) { return Function.prototype.bind.apply(this, arguments) }
var that = this,
slice = function(a, b) { return a.length - (b || 0) ? Array.prototype.slice.call(a, b || 0) : [] },
concat = function(a, b) { return a.length ? b.length ? a.concat(b) : a : b; },
args = slice(arguments, 1);
return function() {
that.apply(obj, concat(args, slice(arguments)));
@maruf89
maruf89 / pre-push
Created April 7, 2014 17:52
Git pre-push hook that will throw an error if you try pushing any code with `DONT PUSH ME` in it
#!/bin/bash
# File lives in .git/hooks/pre-push
# If the following text is found anywhere in the source for HEAD, we will prevent pushing
dont_push_flag="DONT PUSH ME"
flag_found=`git grep --color "$dont_push_flag" HEAD`
if [ -n "$flag_found" ]
then
@maruf89
maruf89 / eventEmitter.js
Created April 25, 2014 18:14
angular event emitter
angular.module('contra.eventEmitter', [])
.factory('eventEmitter', function () {
'use strict';
return {
emitter: function (thing) {
var evt = {},
tick = function tick (fn) { setTimeout(fn, 0); },
debounce = function (fn, args) { if (!fn) { return; } tick(function run () { fn.apply(null, args || []); }); }
if (thing === undefined) { thing = {}; }
@maruf89
maruf89 / Contra.eventEmitter.js
Created May 12, 2014 22:18
Borrowed from Contra and applied to an angular module
angular.module('contra.eventEmitter', [])
.factory('eventEmitter', function () {
'use strict';
return {
emitter: function (thing) {
var evt = {},
tick = function tick (fn) { setTimeout(fn, 0); },
debounce = function (fn, args) { if (!fn) { return; } tick(function run () { fn.apply(null, args || []); }); }
if (thing === undefined) { thing = {}; }
@maruf89
maruf89 / ElasticsearchUpdate
Created June 18, 2014 02:37
Elasticsearch Index Updates
// close the index with `POST` (using `PUT` will throw error)
curl -XPOST localhost:9200/users/_close
// Update with the analysis with a `PUT` (using `POST` will throw error)
curl -XPUT localhost:9200/users/_settings -d '{
"analyzer": {
"ngram_languages": {
"tokenizer": "ngram_languages_tokenizer"
}
},
@maruf89
maruf89 / combiner.coffee
Created June 26, 2014 18:24
Assembles upload chunks into a single file. Originally built for Flow.js using Nodejs
# Usage: Create a new combiner instance for each new object that needs assembling
# And call #add to add each new chunk
#
# combiner = combiners[identifier] or new Combiner(
# numberOfChunks: numberOfChunks
# filename: filename
# identifier: identifier
# directory: @temporaryFolder
# callback: ->
# # destroy reference as it's no longer needed
@maruf89
maruf89 / startfile
Last active August 29, 2015 14:14
Elasticsearch startfile
#!/bin/bash
NAME=elasticsearch
DIR=/opt/${NAME}
PID=/var/run/${NAME}.pid
if [ ! -f $PID ]; then
echo $$ > $PID
fi
##################### Elasticsearch Configuration Example #####################
# This file contains an overview of various configuration settings,
# targeted at operations staff. Application developers should
# consult the guide at <http://elasticsearch.org/guide>.
#
# The installation procedure is covered at
# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/setup.html>.
#
# Elasticsearch comes with reasonable defaults for most settings,
@maruf89
maruf89 / rc.local
Last active August 29, 2015 14:14
startup file for new server
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
@maruf89
maruf89 / .zshrc
Last active August 29, 2015 14:14
My zsh env
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="robbyrussell"
# Example aliases