Skip to content

Instantly share code, notes, and snippets.

@csanz
csanz / encrypt_decrypt.js
Created August 30, 2011 16:06
Simple String Encryption & Decryption with Node.js
function encrypt(text){
var cipher = crypto.createCipher('aes-256-cbc','d6F3Efeq')
var crypted = cipher.update(text,'utf8','hex')
crypted += cipher.final('hex');
return crypted;
}
function decrypt(text){
var decipher = crypto.createDecipher('aes-256-cbc','d6F3Efeq')
var dec = decipher.update(text,'hex','utf8')
@ianmackinnon
ianmackinnon / match.c
Created August 8, 2012 12:01
C Regex multiple matches and groups example
# gcc -Wall -o match match.c && ./match
#
#include <stdio.h>
#include <string.h>
#include <regex.h>
@waynegraham
waynegraham / continentCodes.txt
Created October 22, 2012 16:08
Download and import geonames data
AF,Africa,6255146
AS,Asia,6255147
EU,Europe,6255148
NA,North America,6255149
OC,Oceania,6255151
SA,South America,6255150
AN,Antarctica,6255152
@Cacodaimon
Cacodaimon / GameManager.js
Created December 3, 2012 00:54
Abstract game object class. (Used @ cacodaemon.de)
/*
* Simple JavaScript game manager.
*
* (c) 2012 Guido Krömer <mail@cacodaemon.de>
*
*/
function GameManager () {
var canvas = null;
var ctx = null;
var delta = 0;
@inklesspen
inklesspen / gist:4222841
Created December 6, 2012 08:39
ACLs, context objects, and URL Dispatch in Pyramid
# A worked example based on http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/narr/urldispatch.html#using-pyramid-security-with-url-dispatch
# in your configuration section (typically in myapp/__init__.py)
config.add_route('articles.edit', 'article/{id}/edit', factory='myapp.acl.ArticleACL')
# in myapp/acl.py
class ArticleACL(object):
def __init__(self, request):
# First, we assume this ACL object is used only in routes that provide an article id; if need be, you can add some sanity checking here, or some if/else branching
@kwarrick
kwarrick / fncache.py
Last active May 29, 2024 08:41
Redis-backed LRU cache decorator in Python.
#!/usr/bin/env python
__author__ = 'Kevin Warrick'
__email__ = 'kwarrick@uga.edu'
import cPickle
from functools import wraps
def redis_lru(capacity=5000, slice=slice(None)):
"""
Simple Redis-based LRU cache decorator *.
@Stuk
Stuk / exec.js
Created August 14, 2013 00:15
Wrap Node's `child_process.spawn` with a promise interface that rejects if the process has an error, or exits with a code other than zero.
var spawn = require("child_process").spawn;
var Q = require("q");
/**
* Wrap executing a command in a promise
* @param {string} command command to execute
* @param {Array<string>} args Arguments to the command.
* @param {string} cwd The working directory to run the command in.
* @return {Promise} A promise for the completion of the command.
*/
@staltz
staltz / introrx.md
Last active July 15, 2024 15:43
The introduction to Reactive Programming you've been missing
@gjuric
gjuric / nginx-proxy-geoip
Created May 7, 2015 15:26
nginx - pass GEOIP headers to proxy host
# http block
geoip_city /usr/local/share/GeoIP/GeoIPCity.dat;
geoip_country /usr/local/share/GeoIP/GeoIPCountry.dat;
# location block
proxy_set_header GEOIP_COUNTRY_CODE $geoip_country_code;
proxy_set_header GEOIP_COUNTRY_CODE3 $geoip_country_code3;
proxy_set_header GEOIP_COUNTRY_NAME $geoip_country_name;
@gauravbarthwal
gauravbarthwal / Connecting device to Android Studio on Ubuntu
Created May 11, 2015 11:25
How to run android app on device using Android Studio in Ubuntu
Steps to connect device with Android Studio in Ubuntu:-
1. Enable USB debugging on your device.
2. Go to root and create a file: sudo vi /etc/udev/rules.d/51-android.rules
a. Add the following text in the file:
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"
** Note: vendor id is different for each company.
Company USB Vendor ID
Acer 0502
ASUS 0b05
Dell 413c