Skip to content

Instantly share code, notes, and snippets.

@teebu
teebu / cors-nginx.conf
Last active August 29, 2015 14:27 — forked from alexjs/cors-nginx.conf
Slightly tighter CORS config for nginx
#
# Slightly tighter CORS config for nginx
#
# A modification of https://gist.github.com/1064640/ to include a white-list of URLs
#
# Despite the W3C guidance suggesting that a list of origins can be passed as part of
# Access-Control-Allow-Origin headers, several browsers (well, at least Firefox)
# don't seem to play nicely with this.
#
//console.log(stringDateToEpoch("2016-01-31T21:52:02.607Z"))
var obj = { "rank_history": [
{"date": "2016-02-17T04:27:16.773Z","rank": 121},
{"date": "2016-02-15T05:37:16.773Z","rank": 122},
[1455763092,153],
[1455761092,154],
{"date": "2016-02-14T02:27:16.773Z","rank": 125},
[1455781509,156]
]
@teebu
teebu / jruby-amazon-linux.bash
Created March 3, 2016 04:32 — forked from kainam00/jruby-amazon-linux.bash
Install jruby on Amazon Linux
#!/bin/bash
# Install prerequisites
yum install -y gcc openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel ruby-devel gcc-c++ jq git
# Import key
curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
# Install RVM
curl -sSL https://get.rvm.io | bash -s stable --ruby
@teebu
teebu / elasticsearch.monit
Last active April 15, 2016 19:14 — forked from gacha/elasticsearch.monit
Elasticsearch monit
check process elasticsearch with pidfile /var/run/elasticsearch.pid
start program = "/etc/init.d/elasticsearch start"
stop program = "/etc/init.d/elasticsearch stop"
if 5 restarts within 5 cycles then timeout
if failed host 127.0.0.1 port 9200 protocol http then restart
function getOutputResolution(max_width, max_height, videoInfo) {
var tmp_max_width = 0
var tmp_max_height = 0
// ShrinkToFit: don't scale up videos
max_width = (max_width > videoInfo.width) ? videoInfo.width : max_width
max_height = (max_height > videoInfo.height) ? videoInfo.height : max_height
if (videoInfo.width < videoInfo.height) { // for portrait
tmp_max_width = Math.min(max_width, max_height) // getting the smallest number for width
tmp_max_height = Math.max(max_width, max_height) // getting the biggest number for height
@teebu
teebu / get-endpoints.sh
Created August 27, 2016 03:23 — forked from Mpdreamz/get-endpoints.sh
Get all of elasticsearch's REST endpoints, come up with method names for them and dedup them, Used in newer versions of NEST to generate the raw client (if you only need to pass and receive strings from the client. Scroll down for example output
#!/bin/bash
# This scripts scans the elasticsearch source code for all the registered REST endpoints
# It will put the formatted output in $DEFINITIONOUTPUTFILE
# [MethodName] [HttpVerb] [Route]
ESFOLDER="../elasticsearch"
DEFINITIONOUTPUTFILE="src/Generated/rest-actions.txt"
# Find all the lines that registerHandlers
@teebu
teebu / slugify.js
Created September 14, 2016 21:55 — forked from mathewbyrne/slugify.js
Javascript Slugify
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
@teebu
teebu / ipin.py
Created September 21, 2016 01:24 — forked from urielka/ipin.py
iOS PNG uncrushers based on http://www.axelbrz.com.ar/?mod=iphone-png-images-normalizer with a fix for multiple IDAT
#---
# iPIN - iPhone PNG Images Normalizer v1.0
# Copyright (C) 2007
#
# Author:
# Axel E. Brzostowski
# http://www.axelbrz.com.ar/
# axelbrz@gmail.com
#
# References:
@teebu
teebu / png.rb
Created September 21, 2016 08:04 — forked from AquaGeek/png.rb
Ruby code to reverse iPhone PNG optimizations
# Helper method to fix Apple's stupid png optimizations
# Adapted from:
# http://www.axelbrz.com.ar/?mod=iphone-png-images-normalizer
# https://github.com/peperzaken/iPhone-optimized-PNG-reverse-script/blob/master/Peperzaken/Ios/DecodeImage.php
# PNG spec: http://www.libpng.org/pub/png/spec/1.2/PNG-Contents.html
require 'zlib'
require 'logger'
module PNG
@teebu
teebu / url_slug.js
Created December 9, 2016 02:27 — forked from sgmurphy/url_slug.js
URL Slugs in Javascript (with UTF-8 and Transliteration Support)
/**
* Create a web friendly URL slug from a string.
*
* Requires XRegExp (http://xregexp.com) with unicode add-ons for UTF-8 support.
*
* Although supported, transliteration is discouraged because
* 1) most web browsers support UTF-8 characters in URLs
* 2) transliteration causes a loss of information
*
* @author Sean Murphy <sean@iamseanmurphy.com>