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>
@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
@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.
"""
// ==UserScript==
// @name Show Full Domain on Hacker News posts
// @description Sets full domain on hacker news posts.
// @namespace http://userscripts.org/users/119115
// @include http://news.ycombinator.com/*
// @include https://news.ycombinator.com/*
// @match https://news.ycombinator.com/*
// @match http://news.ycombinator.com/*
// ==/UserScript==
@jtreitz
jtreitz / linear_partition.coffee
Last active December 16, 2015 20:10
Linear partition in Coffeescript (Javascript)
# Linear partition
# Partitions a sequence of non-negative integers into k ranges
# Based on Óscar López implementation in Python (http://stackoverflow.com/a/7942946)
# Also see http://www8.cs.umu.se/kurser/TDBAfl/VT06/algorithms/BOOK/BOOK2/NODE45.HTM
# Dependencies: UnderscoreJS (http://www.underscorejs.org)
# Example: linear_partition([9,2,6,3,8,5,8,1,7,3,4], 3) => [[9,2,6,3],[8,5,8],[1,7,3,4]]
linear_partition = (seq, k) =>
n = seq.length
@danielnorton
danielnorton / AttributedRoundtrip.m
Last active August 9, 2016 13:56
Unexpected roundtrip of HTML through NSAttributedString. This demonstrates a simple HTML file going into an NSAttributedString and then writing that string back out to a new HTML file. The output file is structured very differently than the input file. This was discovered while experimenting with using a UITextView as a rich text editor.
- (NSAttributedString *)loadContent {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"input" ofType:@"html"];
NSData *htmlData = [NSData dataWithContentsOfFile:filePath];
NSDictionary *options = @{
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)
};
@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
@timmyomahony
timmyomahony / postprocess_sekizai.py
Created October 25, 2011 01:11
django-sekizai postprocessor for enabling django-compressor compatibility
"""
Get django-sekizai, django-compessor (and django-cms) playing nicely together
re: https://github.com/ojii/django-sekizai/issues/4
using: https://github.com/jezdez/django_compressor.git
and: https://github.com/ojii/django-sekizai.git@0.5
"""
from compressor.templatetags.compress import CompressorNode
from django.template.base import *
def compress(data, name):
@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]

@jstoiko
jstoiko / gist:5492f8baa69c1722b984
Created June 12, 2015 20:02
Using tox, pyenv and multiple version of python on OSX

Install pyenv using homebrew:

$ brew install pyenv

Install multiple versions of python:

$ pyenv install 3.2.6 3.3.6 3.4.3