Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bgreenlee
bgreenlee / crypto.rb
Created February 26, 2009 06:01
Simple Ruby wrapper for encryption/decryption using OpenSSL
class Crypto
# encrypts data with the given key. returns a binary data with the
# unhashed random iv in the first 16 bytes
def self.encrypt(data, key)
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
cipher.encrypt
cipher.key = key = Digest::SHA256.digest(key)
random_iv = cipher.random_iv
cipher.iv = Digest::SHA256.digest(random_iv + key)[0..15]
encrypted = cipher.update(data)
@naholyr
naholyr / enableMultipleViewRoots.js
Created May 27, 2011 15:23
Allow multiple views roots in Express.js
// Usage:
// var express = require('express')
// require('enableMultipleViewRoots')(express)
module.exports = function(express) {
var old = express.view.lookup;
function lookup(view, options) {
// If root is an array of paths, let's try each path until we find the view
if (options.root instanceof Array) {
@mrbongiolo
mrbongiolo / fql_query_page_photos.fql
Last active June 22, 2016 19:44
Query for FQL to get all photos from a Facebook Page albums and all photos tagged with that Facebook Page
# Formatted for readability
SELECT src, src_height, src_width, src_small, src_small_height, src_small_width
FROM photo
WHERE pid IN (SELECT pid
FROM photo_tag
WHERE subject='243117879034102' )
OR
pid IN (SELECT pid
FROM photo
WHERE aid IN (SELECT aid
@jackdoe
jackdoe / rack-and-mongo.rb
Created March 6, 2012 17:48
mongoid stored rack session Rack::Session::RackAndMongo
# inspired by https://github.com/biilmann/mongo_sessions
require 'rack/session/abstract/id'
class Session
include Mongoid::Document
field :sid
field :data
field :ts, type: Integer
index :sid, unique: true #dont forget Session.create_indexes
def Session.find_by_sid(sid)
Session.first(conditions: {sid: sid})
@bobbydavid
bobbydavid / app.js
Created May 8, 2012 23:46
socket.io in Express 3
var express = require('express')
, http = require('http')
, connect = require('connect')
, io = require('socket.io');
var app = express();
/* NOTE: We'll need to refer to the sessionStore container later. To
* accomplish this, we'll create our own and pass it to Express
* rather than letting it create its own. */
var sessionStore = new connect.session.MemoryStore();
@guerrerocarlos
guerrerocarlos / main.js
Created September 6, 2012 05:07
loading socket.io using require.js
// Require.js allows us to configure shortcut alias
require.config({
// The shim config allows us to configure dependencies for
// scripts that do not call define() to register a module
shim: {
'socketio': {
exports: 'io'
},
'underscore': {
exports: '_'
@ninjascience
ninjascience / Gruntfile.js
Created January 24, 2013 17:52
Gruntfile.js for testing with Jasmine and RequireJS and using Istanbul for coverage.
module.exports = function(grunt) {
'use strict';
// Project configuration.
grunt.initConfig({
meta : {
// Specify where our test files are. Once we get all the tests switched over we can use 'test/js/**/*.spec.js' to automatically load all tests.
specs : ['test/js/src/**/*.spec.js'],
bin : {
coverage: 'js/bin/coverage'
@lukas-vlcek
lukas-vlcek / gist:4673027
Last active January 19, 2021 15:03
Čeština v elasticsearch
#!/bin/sh
# download
wget http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.20.4.zip
# unzip and start
unzip elasticsearch-0.20.4.zip
cd elasticsearch-0.20.4
# remove data in case you have defined some analyzers in the past (e.g. stop/start)
rm -rf data/
@PRotondo
PRotondo / traceroute.hs
Last active July 30, 2017 15:53
Haskell traceroute over icmp
#!/usr/bin/env runhaskell
-- Haskell traceroute over icmp
-- now with ByteString to avoid new errors produced
-- by the deprecated recvFrom from Network.Socket
import Control.Monad
import Data.Bits(complement)
import Data.ByteString(unpack,pack)
import Data.List
#! /usr/bin/env ruby
require 'rubygems'
require 'fog'
require 'fileutils'
require 'yaml'
module Apollo
class AwsConsole