Skip to content

Instantly share code, notes, and snippets.

@padde
padde / test.json
Created January 8, 2015 10:24
some json
{
"hello": "world"
}
@padde
padde / ilike.sql
Created January 8, 2015 15:02
ILIKE
SELECT * FROM posts WHERE body ILIKE '%zweitag%'
@padde
padde / tsvector.sql
Created January 8, 2015 15:03
to_tsvector
SELECT to_tsvector('I like to go swimming');
--------------------------
'go':4 'like':2 'swim':5
@padde
padde / tsvector_german_broken.sql
Created January 8, 2015 15:04
to_tsvector (german with english analysis)
SELECT to_tsvector('Ich würde gerne schwimmen gehen');
----------------------------------------------------
'gehen':5 'gern':3 'ich':1 'schwimmen':4 'würde':2
@padde
padde / tsvector_german.sql
Created January 8, 2015 15:04
to_tsvector (german)
SELECT to_tsvector('german', 'Ich würde gerne schwimmen gehen');
------------------------------
'geh':5 'gern':3 'schwimm':4
@padde
padde / post.rb
Created January 8, 2015 15:05
Post model with pg_search
class Post < ActiveRecord::Base
include PgSearch
pg_search_scope :search,
against: :body,
using: {tsearch: {dictionary: 'german'}}
end
@padde
padde / partial_application.rb
Last active August 29, 2015 14:13
Proc#with – Partial Application
require 'forwardable'
class Proc
def with(*arguments, &block)
proc do |*remaining_arguments|
call(*remaining_arguments, *arguments, &block)
end
end
end
@padde
padde / devise.rb
Last active August 29, 2015 14:22
Rails + Devise + RSpec = ❤️
# spec/support/devise.rb
module DeviseFeatureHelpers
def sign_in(user = nil, scope = :user)
user ||= build_stubbed :user
login_as user, scope: scope
end
end
RSpec.configure do |config|
@padde
padde / regex_interpolation.exs
Last active August 29, 2015 14:22
Elixir Regex Interpolation – do not use in production
defmodule Regex.InterpolationError do
defexception [:message]
end
defmodule Regex.Interpolation do
def wrap(regex = %Regex{opts: modifiers}) do
Regex.source(regex)
|> do_wrap(modifiers)
end
@padde
padde / keybase.md
Created July 19, 2015 13:17
Keybase proof

Keybase proof

I hereby claim:

  • I am padde on github.
  • I am padde (https://keybase.io/padde) on keybase.
  • I have a public key whose fingerprint is 7B8E 3327 8E52 E3E1 8392 92AE CCBB 382F 5F9D 1786

To claim this, I am signing this object: