Skip to content

Instantly share code, notes, and snippets.

View soey's full-sized avatar

Samuel Oey soey

  • CAPinside
  • Hamburg
View GitHub Profile
@soey
soey / gist:7794712
Created December 4, 2013 20:15
monkey patch devise token authenticable to survive baked in cookies..
# monkey patch devise token authenticable to have tokens surviving in cookies
require 'securerandom'
module Devise
module Models
module TokenAuthenticatable
module ClassMethods
# Generate a token checking if one does not already exist in the database.
def authentication_token
@soey
soey / gist:6311279
Last active December 21, 2015 13:18
alternatives to insert into select causing read locks on innodb
SELECT * FROM tbl1 INFO OUTFILE '/tmp/tbl1.txt';
LOAD DATA INFILE '/tmp/tbl1.txt' INTO TABLE tbl2;
//see http://www.mysqlperformanceblog.com/2006/07/12/insert-into-select-performance-with-innodb-tables/
@soey
soey / gist:6306062
Last active December 21, 2015 12:29
get information about a mysql table
# from http://www.mysqlperformanceblog.com/2008/03/17/researching-your-mysql-table-sizes/
SELECT count(*) tables,
-> concat(round(sum(table_rows)/1000000,2),'M') rows,
-> concat(round(sum(data_length)/(1024*1024*1024),2),'G') data,
-> concat(round(sum(index_length)/(1024*1024*1024),2),'G') idx,
-> concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size,
-> round(sum(index_length)/sum(data_length),2) idxfrac
-> FROM information_schema.TABLES
-> WHERE table_name like "foo";
@soey
soey / cobra.rb
Created March 5, 2011 20:16
Cobra allows conditional rendering of nested markup.
#
# LICENSE
#
# The MIT License
#
# Copyright (c) 2011 Samuel Oey, Ubilabs GmbH (oey@ubilabs.net)
#
# 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
#Change this:
ActionController::Base.class_eval do
def perform_action
perform_action_without_rescue
end
end
#to: