Skip to content

Instantly share code, notes, and snippets.

View phoet's full-sized avatar
:shipit:
Shippin Stuffs 🚀

Peter Schröder phoet

:shipit:
Shippin Stuffs 🚀
View GitHub Profile
class ActiveRecord::ConnectionAdapters::MysqlAdapter
def create_partitioned_table(table_name, &block)
partition_sql = <<-sql
ENGINE=InnoDB AUTO_INCREMENT=610925 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
partition by range (to_days(created_at))
(
partition p_0 values LESS THAN (to_days('2000-01-01')),
sql
partitions = (-4..4).collect do |i|
# In your test_helper.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
@anhang
anhang / localStorage.js
Created July 20, 2011 23:07
HTML5 Local Storage with Expiration
AZHU.storage = {
save : function(key, jsonData, expirationMin){
if (!Modernizr.localstorage){return false;}
var expirationMS = expirationMin * 60 * 1000;
var record = {value: JSON.stringify(jsonData), timestamp: new Date().getTime() + expirationMS}
localStorage.setItem(key, JSON.stringify(record));
return jsonData;
},
load : function(key){
if (!Modernizr.localstorage){return false;}
@Sjors
Sjors / robot_user_agents.rb
Created August 3, 2011 00:08
Recognize search engines and spammers using user-agents.org
require 'net/http'
require 'xmlsimple'
url = "http://www.user-agents.org/allagents.xml"
xml_data = Net::HTTP.get_response(URI.parse(url)).body
data = XmlSimple.xml_in(xml_data)
agents = data['user-agent'].select{|agent| type = agent["Type"].first; type.include?("R") || type.include?("S")}
agent_names = agents.collect {|agent| agent["String"].first}
@bkimble
bkimble / gist:1365005
Last active March 22, 2024 19:21
List local memcached keys using Ruby
#!/usr/bin/env ruby
# List all keys stored in memcache.
# Credit to Graham King at http://www.darkcoding.net/software/memcached-list-all-keys/ for the original article on how to get the data from memcache in the first place.
require 'net/telnet'
headings = %w(id expires bytes cache_key)
rows = []
@steve9001
steve9001 / application.rb
Created December 7, 2011 16:18
Rails middleware to provide information about errors during requests
module MyApp
class Application < Rails::Application
if Rails.env == 'test'
require 'diagnostic'
config.middleware.use(MyApp::DiagnosticMiddleware)
end
end
end
@jimbojsb
jimbojsb / gist:1630790
Created January 18, 2012 03:52
Code highlighting for Keynote presentations

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2:

@erikh
erikh / hack.sh
Created March 31, 2012 07:02 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active April 24, 2024 12:19
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@gs
gs / gist:3096729
Created July 12, 2012 08:33
Sublime 2 Plugins that I found useful in RoR developement