Skip to content

Instantly share code, notes, and snippets.

@jcsrb
jcsrb / InstallHaProxy.sh
Last active August 31, 2016 10:51
RHEL 6.7 Install HAProxy From Source (1.6.9 release pre configured). chmod +x InstallHaProxy.sh then ./InstallHaProxy.sh
#!/bin/bash
### VARIABLES ###
PRE_PACK="openssl-devel pcre-devel make gcc"
VER="1.6.9"
# Setup Colours
black='\E[30;40m'
red='\E[31;40m'
@jcsrb
jcsrb / InstallHaProxy.sh
Created August 29, 2016 15:41 — forked from ChrisMcKee/InstallHaProxy.sh
Centos 6.5 Install HAProxy From Source (1.5.1 release pre configured). chmod +x InstallHaProxy.sh then ./InstallHaProxy.sh
#!/bin/bash
### VARIABLES ###
PRE_PACK="openssl-devel pcre-devel make gcc"
VER="1.5.1"
# Setup Colours
black='\E[30;40m'
red='\E[31;40m'
@jcsrb
jcsrb / rate_limit.js
Created August 22, 2016 12:39 — forked from mattheworiordan/rate_limit.js
Rate limiting function calls with JavaScript and Underscore.js
/* Extend the Underscore object with the following methods */
// Rate limit ensures a function is never called more than every [rate]ms
// Unlike underscore's _.throttle function, function calls are queued so that
// requests are never lost and simply deferred until some other time
//
// Parameters
// * func - function to rate limit
// * rate - minimum time to wait between function calls
// * async - if async is true, we won't wait (rate) for the function to complete before queueing the next request
#/bin/bash
#-- Script to automate https://help.github.com/articles/why-is-git-always-asking-for-my-password
REPO_URL=`git remote -v | grep -m1 '^origin' | sed -Ene's#.*(https://[^[:space:]]*).*#\1#p'`
if [ -z "$REPO_URL" ]; then
echo "-- ERROR: Could not identify Repo url."
echo " It is possible this repo is already using SSH instead of HTTPS."
exit
fi
@jcsrb
jcsrb / select.js
Last active October 10, 2018 20:33
How open a <select> element programmatically
//Thank to @Formstone https://github.com/Formstone/Selecter/blob/master/src/jquery.fs.selecter.js
if (window.document.createEvent) { // All
var evt = window.document.createEvent("MouseEvents");
evt.initMouseEvent("mousedown", false, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
el.dispatchEvent(evt);
} else if (el.fireEvent) { // IE
el.fireEvent("onmousedown");
}
@jcsrb
jcsrb / style.js
Last active August 29, 2015 14:12 — forked from potch/style.js
// Bad
"Your Framework Sucks."
// Bad
"Browserify? Have you heard about WebPack?"
// Bad
"Ember vs Angular: 10 Things You Should Know"
(function (){
var ua = navigator.userAgent.toLowerCase();
var android = /Android/gi.test(ua);
var iOS = /(iPad|iPhone|iPod)/gi.test(ua);
if(android) { $("body").addClass("device-running-android"); }
if(iOS) { $("body").addClass("device-running-ios"); }
if(!iOS && !android) { $("body").addClass("device-not-running-ios-or-android"); }
})();
require 'net/http'
module Net
class HTTP
def self.enable_debug!
raise "You don't want to do this in anything but development mode!" unless Rails.env == 'development'
class << self
alias_method :__new__, :new
def new(*args, &blk)
instance = __new__(*args, &blk)
instance.set_debug_output($stderr)
switch dots.html().length
when 3 then dots.html("")
when 2 then dots.html("...")
when 1 then dots.html("..")
when 0 then dots.html(".")
else dots.html("...")
var validateAgeOlderOrExactly = function(date_string, age_limit_year, age_limit_month) {
var ageLimitDate, birthDate, today;
if (age_limit_month == null) {
age_limit_month = 0;
}
today = new Date();
birthDate = new Date(date_string);
ageLimitDate = new Date(today.getFullYear() - age_limit_year, today.getMonth() - age_limit_month, today.getDate());
return birthDate <= ageLimitDate;
};