Skip to content

Instantly share code, notes, and snippets.

View no-dashes's full-sized avatar

Peter Horn no-dashes

View GitHub Profile
@no-dashes
no-dashes / base54.rb
Last active September 15, 2021 08:31
Base54
module Base54
L = %w{0 1 2 3 4 5 6 7 8 9
A B C D E F G H K L
M N P Q R T U V W X
Y a b c d e f g h i
j k m n p q r s t u
v w x z}
WHITESPACE = [' ', '-', '_', '.', '+']
function enableReorder() {
$('*[data-reorder-path]').sortable({
update: function(event, ui) {
var ul = $(this);
var ids = ul.children("*[data-child-id]").map(function(){
return $(this).data("child-id");
}).toArray().join(",");
$.ajax(ul.data('reorderPath'), {
data: {ids: ids}
});
# Aus dem Controller kommen:
# - @employee
# - @context (alle infos, die Liquid benutzen soll/darf)
# - @template (Das Ding von oben)
- content_for :header do
= Liquid::Template.parse(@template.header).render(@context)
- content_for :submenu do
= Liquid::Template.parse(@template.submenu).render(@context)
@no-dashes
no-dashes / gist:2478161
Created April 24, 2012 09:14
ActiveRecord#becomes doesn't destroy associations any more
# Normally if you do
class A < ActiveRecord::Base
belongs_to :c
end
class B < A
end
b = B.new
b.c = C.new
@no-dashes
no-dashes / gist:2049918
Created March 16, 2012 12:43
Filter with & on Hashes
class Hash
def &(*ks)
kk = self.keys
ks = ks.flatten
self.reject{ |k,v| !ks.member?(k) }
end
end
> {a:1, b:2} & 1
=> {}
@no-dashes
no-dashes / gist:1807818
Created February 12, 2012 10:42
Tabulatr Presets
Tabulatr.config do |config|
#...
config.column_presets({
config.column_presets({
:action_column => {:width => '100px'},
:smallint => { :width => '55px', :filter_width => '30px', :align => 'right' },
:id => :smallint,
:sid => { :width => '200px', :filter_width => '170px', :filter => :like },
:title => { :filter => :like },
:count => { :map => false, :width => '40px', :filter => false, :align => 'right' },
see https://github.com/metaminded/time_period
@no-dashes
no-dashes / PgTable.rb
Created January 6, 2012 13:14
How to iterate over the PostgreSQL schemata in an migration (or the like)
class PgTable < ActiveRecord::Base
SystemSchemaNames = ['public', 'information_schema', 'pg_catalog']
def self.each_schema_execute(&block)
tenant_schemas.each do |schemaname|
set_search_path(schemaname)
yield(self.connection)
end
end
@no-dashes
no-dashes / gist:1502996
Created December 20, 2011 19:57
localization games
# First, I put this into the application helper
module ApplicationHelper
class T
instance_methods.each { |m| undef_method m unless m =~ /^((object_id$)|(__))/ }
def method_missing(sym, *args, &block)
@str = @str ? "#{@str}.#{sym}" : sym.to_s
self