Skip to content

Instantly share code, notes, and snippets.

@tskogberg
tskogberg / gist:3882133
Created October 12, 2012 23:03
Slå upp ord i NE (www.ne.se)
# Slå upp ord i NE
require 'nokogiri'
require 'open-uri'
query_word = URI.encode('gamäng')
# alt doc.search('.ENC').text.lines.to_a[1].strip
doc = Nokogiri::HTML(open("http://www.ne.se/sok?q=#{query_word}"))
first_hit = doc.xpath('//span[@class="ENC"]').text.lines.map(&:strip)[1]
class String
def hello
puts "hello from String"
end
end
class MyString < String
def hello
puts "hello from MyString"
end
# Ways to resolve hostname
Socket::getaddrinfo("2.1.1.2")
Resolv::getname("2.1.1.2")
module Foo
def bar
end
end
class Baz
include Foo
def Kaz
end
" Promote variable to RSpec let.
" Based on
" https://github.com/myronmarston/vim_files/commit/ed60919f1857359da617491a7d7c14e8d4befae0
"
" Given either of
"
" foo = x
" @foo = x
"
" on the current line or in a given range (e.g. visual range),
/* Make a trigger to count rows in a table */
CREATE TABLE rowcount (
table_name text NOT NULL,
total_rows bigint,
PRIMARY KEY (table_name));
CREATE OR REPLACE FUNCTION count_rows()
RETURNS TRIGGER AS
'
" Open public I18n translation files
nmap <leader>pu :tabe <BAR> :args config/locales/{en,sv,de}.yml <BAR> vertical all<CR>
" Open admin I18n translation files
nmap <leader>ad :tabe <BAR> :args config/locales/admin.{en,sv,de}.yml <BAR> vertical all<CR>
# personal settings for tmux
#
# changed bindings
# vim movments keys for tmux (hjkl)
set-window-option -g mode-keys vi
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
@tskogberg
tskogberg / rails
Created April 11, 2017 07:10
Heroku: Fix "SignalException: SIGHUP" errors
#!/usr/bin/env ruby
APP_PATH = File.expand_path("../../config/application", __FILE__)
require_relative "../config/boot"
# Make a clean exit on Heroku while running a rails console.
# Without this we'll get a "SignalException: SIGHUP" error in honeybadger.
if ENV["DYNO"]
if ["c", "console"].include?(ARGV.first)
Signal.trap("SIGHUP") { exit 0 }
end