Skip to content

Instantly share code, notes, and snippets.

@raggi
raggi / sinatra_metal.rb
Created March 18, 2009 15:40
sinatra as rails metal example - mostly unnecessary
require 'sinatra/metal'
class SinatraMetal < Sinatra::Base
include Sinatra::Metal
get '/sinatra' do
'hello sinatra!'
end
end
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
@dkubb
dkubb / ev.rb
Created March 16, 2011 22:13
Poor-man's Embedded Value
class User
include DataMapper::Resource
property :id, Serial
property :username, String, :required => true, :unique => true
property :address_street_address, String
property :address_location, String
property :address_subdivision, String
property :address_country, String
@britishtea
britishtea / trades.rb
Created June 27, 2011 22:01
Bitcoin trade data
# I turned the script into a Ruby gem. To install it, first install Rubygems if you haven't already. Instructions are here: https://rubygems.org/pages/download. Next type: sudo gem install trades
#
# To run the script type:
# trades
#
# Or if you only want to see trades from specific exchanges:
# trades mtgoxUSD thUSD britcoinGBP
#
# You can specify as many exchanges as you want. Just make sure you use the same name Bitcoincharts uses.
#
@durango
durango / items.php
Created June 29, 2011 01:12
Just showing someone the basics of closures...
<?php
class item {
public $player_id, $ids, $sql, $vars = array();
private $functions = array();
function __construct($sql=null) {
$this->sql = $sql;
$this->sql->query('SHOW FIELDS FROM items');
for($x=0;$x<$this->sql->rows;$x++) {
$this->sql->fetch($x);
require "rubygems"
require "datamapper"
DataMapper.setup(:default, "sqlite::memory:")
DataMapper::Logger.new(STDOUT, :debug)
class Recipe
include DataMapper::Resource
property :id, Serial
@rkh
rkh / response_size.rb
Created August 10, 2011 10:12 — forked from jergason/app.rb
Checking size of each request
require 'rack'
##
# Tries to calculate size of the complete response.
# This middleware should be chained in front of everything else.
# Middleware taking care of compression, etag handling etc could
# produce wrong results.
#
# Leaves streaming intact and does work file bodies from sockets
# and files.
anonymous
anonymous / gist:5408941
Created April 18, 2013 00:37
// Make sure the socket is coming from our app by matching the session id
socketServer.set('authorization', function (data, accept) {
cookieParser(data, {}, function(err) {
if (err) {
accept(err, false);
} else {
config.sessionStore.load(data.signedCookies[config.sessionKey], function(err, session) {
if (err || !session) {
accept('Session error', false);
} else {
@Amanieu
Amanieu / chase_lev.cpp
Last active January 20, 2023 11:57
Chase-Lev deque implementation
// Copyright (c) 2013 Amanieu d'Antras
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
#!/usr/bin/env ruby -w
# brew-services(1) - Easily start and stop formulas via launchctl
# ===============================================================
#
# ## SYNOPSIS
#
# [<sudo>] `brew services` `list`<br>
# [<sudo>] `brew services` `restart` <formula><br>
# [<sudo>] `brew services` `start` <formula> [<plist>]<br>