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 / 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 / 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 / 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 / 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 / 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 / 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)));