Skip to content

Instantly share code, notes, and snippets.

Sjoerd Andringa s-andringa

  • Questionmark (@q-m)
  • Amsterdam
Block or report user

Report or block s-andringa

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@s-andringa
s-andringa / renumber_position_column_postgres.sql
Last active Aug 29, 2015
Renumber a position column which is scoped to another column, useful before adding a unique index / null constraint. (Keywords: Postgres, SQL, Reorder scoped position column, row_number in UPDATE clause)
View renumber_position_column_postgres.sql
-- Table in question:
CREATE TABLE product_tags (
id integer NOT NULL,
product_id integer NOT NULL,
tag_id integer NOT NULL,
"position" integer
);
-- Renumber the position column based on row number in partition:
UPDATE product_tags pt
View dsl_basic.rb
module Characteristics
class Describer
def initialize(base)
@base = base
end
def eyes(nr)
p "#{@base.name} has #{nr} eyes."
end
@s-andringa
s-andringa / Locales.yml
Created Sep 19, 2012
Amsrb talk 18 sept - exceptions_app in Rails 3.2
View Locales.yml
# config/locales/en.yml
en:
exception:
show:
not_found:
title: "Not Found"
description: "The page you were looking for does not exists."
internal_server_error:
title: "Internal Server Error"
@s-andringa
s-andringa / meta_code.rb
Created Mar 4, 2012
Meta Code converts itself into a highlighted HTML or PDF document.
View meta_code.rb
require "coderay"
require "pdfkit"
require File.join(File.dirname(__FILE__), "styles/tomorrow_night")
module Meta
class Code
attr_reader :creator
def initialize(options = {})
@creator = options[:creator]
@s-andringa
s-andringa / Countries
Created Feb 25, 2011
Countries of the world. Copy-pastable for testing long word lists.
View Countries
Afghanistan
Albania
Algeria
Andorra
Angola
Antigua & Deps
Argentina
Armenia
Australia
Austria
@s-andringa
s-andringa / constant_gardener.rb
Created Dec 28, 2010
Deal with bitmask-form options & Safely monkey patch Ruby gems
View constant_gardener.rb
class ConstantGardener
def self.create(*booleans)
Class.new do
def initialize(bitmask)
@bitmask = bitmask
end
booleans.each_with_index do |b, i|
const_set b.to_s.upcase, 2**i
View setting class variables.rb
class Object
def metaclass
class << self; return self; end
end
end
class Foo
# 1. def within class definition
def self.set_a
View strange behaviour of class variables.rb
class Object
def metaclass
class << self; self; end
end
end
# - Normal cases -
class Foo
@@bar = 0
View what is has_remote.rb
class User < ActiveRecord::Base
def email
# Make REST call, parse response, extract email address and return it.
# Probably not the most concise and expressive code.
end
end
# Is more or less equal to:
class RemoteUser < ActiveResource::Base
You can’t perform that action at this time.