Skip to content

Instantly share code, notes, and snippets.

View noodlehaus's full-sized avatar

noodlehaus noodlehaus

View GitHub Profile
@bryanthompson
bryanthompson / cache_helper.rb
Created January 14, 2010 22:08
Simple fragment caching in sinatra
require 'sinatra/base'
class CacheHelper
module Sinatra
module Helpers
def cache(name, options = {}, &block)
if cache = read_fragment(name, options)
@_out_buf << cache
else
pos = @_out_buf.length
@hubgit
hubgit / ElasticSearch.php
Created February 16, 2010 17:20
ElasticSearch class for PHP
<?php
// http://www.elasticsearch.com/docs/elasticsearch/rest_api/
class ElasticSearch {
public $index;
function __construct($server = 'http://localhost:9200'){
$this->server = $server;
}
@clindsey
clindsey / install.sh
Created March 10, 2011 19:53
my javascript syntax vim file, osx 10.7
#!/bin/bash
sudo mv /usr/share/vim/vim73/syntax/javascript.vim /usr/share/vim/vim72/syntax/javascript.vim.old
mkdir -p ~/.vim/syntax
mkdir -p ~/.vim/colors
ln -s `pwd`/javascript.vim ~/.vim/syntax/javascript.vim
@tanepiper
tanepiper / media_streamer.coffee
Created April 6, 2011 18:42
Media streaming app in expressjs. It reads a directory of music files and outputs an audio tag pointing to it, and serving the file up as the correct OGG media content
fs = require 'fs'
path = require 'path'
util = require 'util'
express = require 'express'
app = module.exports = express.createServer()
app.get '/', (req, res, next) ->
music_path = path.join __dirname, 'music'
fs.readdir music_path, (error, files) ->
output = []
@adaburrows
adaburrows / functional_php_web_app.php
Created April 26, 2011 05:31
Sketch of how to make a functional style controller in PHP
<?php
/**
* This is by no means complete, but it's a sketch of an idea I had to create a
* classless functional style framework for PHP.
*
* It might turn out to be something cool!
*/
// This function allows creating a new function from two functions passed into it
function compose(&$f, &$g) {
@adaburrows
adaburrows / compose_functions.php
Created April 26, 2011 06:24
Composing functions in PHP
<?php
/**
* Just trying out more functional programming in PHP
* This gist provides some basic utility functions for:
* + Working with functions
* + Working with arrays
*/
// This function allows creating a new function from two functions passed into it
function compose(&$f, &$g) {
@fwielstra
fwielstra / api.js
Created June 14, 2011 14:46
An example NodeJS / Mongoose / Express application based on their respective tutorials
/* The API controller
Exports 3 methods:
* post - Creates a new thread
* list - Returns a list of threads
* show - Displays a thread and its posts
*/
var Thread = require('../models/thread.js');
var Post = require('../models/post.js');
@mxriverlynn
mxriverlynn / 1-ModelWithChangedEvents.js
Created June 15, 2011 03:12
simple backbone.js examples
var SomeModel = Backbone.Model.extend({});
someModel = new SomeModel();
someModel.bind("change", function(model, collection){
alert("You set some_attribute to " + model.get('some_attribute'));
});
someModel.set({some_attribute: "some value"});
@felixge
felixge / command.sh
Created October 29, 2011 13:43
Bash stuff for fighting a weak DOS attack
# Here a few bash one-liners that helped me analyze / fight a weak DOS attack against debuggable.com. Mostly for future reference.
# The attacker was opening lots of tcp connections without sending data, I believe it's called a SYN flood, see: http://tools.ietf.org/html/rfc4987#section-3.2
# Step 0: Check what is going on at port 80
$ netstat -tan | grep ':80 ' | awk '{print $6}' | sort | uniq -c
# Step 1: Increase the number of available fds
$ ulimit -n 32000
# Step 2: Restart your webserver, for me:
@fairchild
fairchild / Gemfile
Created December 7, 2011 09:58
An example sinatra omniauth client app
source :rubygems
gem 'sinatra'
gem 'json'
gem 'omniauth'
gem 'omniauth-oauth2'
gem 'omniauth-github'
# gem 'omniauth-att', :path => File.expand_path("./../../omniauth-att", __FILE__)
gem 'thin'