Skip to content

Instantly share code, notes, and snippets.

View andreif's full-sized avatar
👾
invading spaces

Andrei Fokau andreif

👾
invading spaces
View GitHub Profile
@btucker
btucker / cache.rb
Created March 26, 2010 19:25
Memcached action caching for Sinatra (doesn't work in sinatra >= 1.0)
# Adds support for passing a :cache parameter to action definitions, eg:
#
# get '/state_map/?', :cache => 'state_map' do
# ...
# end
#
# :cache can also simply be passed true, in which case the route definition is used as the base
# key name. In all cases, any params are also included in the key.
#
# Author: ben tucker <ben@btucker.net>
@micktwomey
micktwomey / client.py
Created October 1, 2010 13:03
python multiprocessing socket server example
import socket
if __name__ == "__main__":
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("localhost", 9000))
data = "some data"
sock.sendall(data)
result = sock.recv(1024)
print result
sock.close()
@ches
ches / db.rake
Created October 17, 2010 05:45
Rake task to open MongoDB console for a Rails app with Mongoid
namespace :db do
desc 'Open a MongoDB console with connection parameters for the current Rails.env'
task :console => :environment do
conn = Mongoid.master.connection
args = []
args << "--username=#{conn.username}" if conn.username rescue nil
args << "--password=#{conn.password}" if conn.password rescue nil
args << "--host=#{conn.host}"
args << "--port=#{conn.port.to_s}"
args << Mongoid.master.name
@ches
ches / gist:630625
Created October 17, 2010 07:23
.irbrc for logging goodies like SQL/Mongo queries to $stdout if in Rails 3 console
# .irbrc to log goodies like SQL/Mongo queries to $stdout if in Rails 3 console
if defined?(Rails) && Rails.respond_to?(:logger)
require 'logger'
Rails.logger = Logger.new($stdout)
if defined?(Mongoid)
Mongoid.logger = Rails.logger
end
end
@mathiasbynens
mathiasbynens / appify
Created November 12, 2010 13:46 — forked from subtleGradient/appify
appify — create the simplest possible Mac app from a shell script
#!/bin/bash
if [ "$1" = "-h" -o "$1" = "--help" -o -z "$1" ]; then cat <<EOF
appify v3.0.1 for Mac OS X - http://mths.be/appify
Creates the simplest possible Mac app from a shell script.
Appify takes a shell script as its first argument:
`basename "$0"` my-script.sh
@enaeseth
enaeseth / yaml_ordered_dict.py
Created February 25, 2011 19:54
Load YAML mappings as ordered dictionaries
import yaml
import yaml.constructor
try:
# included in standard lib from Python 2.7
from collections import OrderedDict
except ImportError:
# try importing the backported drop-in replacement
# it's available on PyPI
from ordereddict import OrderedDict
// Original code from http://www.blog.highub.com/mobile-2/a-fix-for-iphone-viewport-scale-bug/
var metas = document.getElementsByTagName('meta');
var i;
if (navigator.userAgent.match(/iPhone/i)) {
for (i=0; i<metas.length; i++) {
if (metas[i].name == "viewport") {
metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
}
}
@mralex
mralex / sinatra-memcacher.rb
Created May 5, 2011 05:41
Simple memcached helper for Sinatra.
require 'sinatra/base'
require 'memcached'
module Sinatra
module Memcacher
module Helpers
def cache(key, &block)
return block.call unless options.memcacher_enabled
begin
@ryanb
ryanb / rails_3_1_rc4_changes.md
Created May 6, 2011 01:10
The Changelogs for Rails 3.1 Beta 1

Railties 3.1 RC4

  • The new rake task assets:clean removes precompiled assets. [fxn]

  • Application and plugin generation run bundle install unless --skip-gemfile or --skip-bundle. [fxn]

  • Fixed database tasks for jdbc* adapters #jruby [Rashmi Yadav]

  • Template generation for jdbcpostgresql #jruby [Vishnu Atrai]

@jonovik
jonovik / codegen.py
Created May 20, 2011 07:56 — forked from mattbasta/codegen.py
A module to "unparse" a Python AST tree.
# -*- coding: utf-8 -*-
"""
codegen
~~~~~~~
Extension to ast that allow ast -> python code generation.
:copyright: Copyright 2008 by Armin Ronacher.
:license: BSD.
"""