Skip to content

Instantly share code, notes, and snippets.

@ndbroadbent
ndbroadbent / gist:5097601
Last active April 29, 2016 02:35
Wrap jQuery events and callbacks with try...catch blocks. Original code from: https://github.com/airbrake/airbrake-js/blob/master/src/notifier.js#L173
/*
* Add hook for jQuery.fn.on function, to manualy call window.Airbrake.captureException() method
* for every exception occurred.
*
* Let function 'f' be binded as an event handler:
*
* $(window).on 'click', f
*
* If an exception is occurred inside f's body, it will be catched here
* and forwarded to captureException method.
@celldee
celldee / gist:4241084
Created December 8, 2012 17:19
Example RabbitMQ configuration file - rabbitmq.config
# /etc/rabbitmq/rabbitmq.config
#
# Follow the instructions on RabbitMQ website to create certificate authority and certificates -
#
# http://www.rabbitmq.com/ssl.html
#
[
{rabbit, [
{tcp_listeners,[{"127.0.0.1",5672}]},
@chrisallick
chrisallick / gist:3990089
Created October 31, 2012 21:42
Autoplay audio on the ipad or iphone using webkitaudiocontext instead of audio tag
AudioSFX = function( _p, _autoplay ) {
var self = this;
var parent = _p;
this.sounds = new Array();
this.context = new webkitAudioContext();
this.autoplay = _autoplay;
this.play = function( sound ) {
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active May 22, 2024 05:53
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@LeZuse
LeZuse / detect.py
Created May 2, 2012 18:28
Flask browser detection
browser = request.user_agent.browser
version = request.user_agent.version and int(request.user_agent.version.split('.')[0])
platform = request.user_agent.platform
uas = request.user_agent.string
if browser and version:
if (browser == 'msie' and version < 9) \
or (browser == 'firefox' and version < 4) \
or (platform == 'android' and browser == 'safari' and version < 534) \
or (platform == 'iphone' and browser == 'safari' and version < 7000) \
@fernandoaleman
fernandoaleman / Linux Static IP
Created March 23, 2012 16:20
How To Configure Static IP On CentOS 6
## Configure eth0
#
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED="yes"
ONBOOT=yes
HWADDR=A4:BA:DB:37:F1:04
TYPE=Ethernet
BOOTPROTO=static
@jmibanez
jmibanez / gist:2140974
Created March 20, 2012 20:29
Using restify with connect
// Restify server config here
var server = restify.createServer({
name: 'restify-test',
version: '1.0.0',
});
// ...
// Connect config here
var connectApp = connect()
@Integralist
Integralist / errorhandler.js
Created January 12, 2012 09:23
Error Handling with RequireJs
define(function(){
return function(errObject) {
requireType = errObject.requireType;
requireModules = errObject.requireModules.trim().split(' ');
console.log(requireType, requireModules);
};
});
@paulirish
paulirish / rAF.js
Last active March 22, 2024 00:00
requestAnimationFrame polyfill
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
@jimjeffers
jimjeffers / html5VideoAspectRatioAdjustment.coffee
Created September 15, 2011 13:24
Breaking the HTML5 Video Aspect Ratio
# Just an example.
# @video is a direct reference to a '<video>' element.
# $() is assuming jQuery is being used in this example.
@video.addEventListener("loadedmetadata", (event) =>
actualRatio = @video.videoWidth/@video.videoHeight
targetRatio = $(@video).width()/$(@video).height()
adjustmentRatio = targetRatio/actualRatio
$(@video).css("-webkit-transform","scaleX(#{adjustmentRatio})")
)