Skip to content

Instantly share code, notes, and snippets.

View tmichel's full-sized avatar

Tamás Michelberger tmichel

View GitHub Profile
@tmichel
tmichel / diff.sh
Created December 17, 2015 09:37
Diff output of two commands without temporary files
# source: http://stackoverflow.com/questions/3800202/diff-output-from-two-programs-without-temporary-files
diff -y <(git st | grep rb | cut -c 4-) <(find app -name *product.rb)
@tmichel
tmichel / gb-rename.sh
Last active October 16, 2015 08:58
gb gorename shim
#!/bin/bash
# Usage: gb rename [gorename options]
# Example:
#
# gb rename -from '"mypackage".AwesomeStruct' -to "EvenMoreAwesomeStruct"
#
# Install: drop this file on your $PATH somewhere ($HOME/bin seems cool) and you're done.
if [ "$1" = "help" ]; then
gorename --help
@tmichel
tmichel / elm_sprockets.rb
Last active July 29, 2017 03:38
Elm Rails 4.2 integration (Sprockets 3.x)
# Elm integration for Sprockets 3.x (Rails 4.2)
#
# Revised version of a Sprockets 3.x processor for Elm. It supports
# dependencies. One little quirk is that only .js.elm files are
# requireable in application.js.
#
# How to use it?
#
# Put this file in your config/initializers/ and create
# app/assets/javascripts/MyModule.js.elm and require it in your
@tmichel
tmichel / gist:0cd075caf2316220d0b4
Created September 25, 2015 13:21
URI parse bug in ruby 2.1
$ docker run --rm -it ruby:2.2 ruby -ruri -e "puts URI('http://accessibility_checker.siteimprove.com')"
http://accessibility_checker.siteimprove.com
$ docker run --rm -it ruby:2.1 ruby -ruri -e "puts URI('http://accessibility_checker.siteimprove.com')"
/usr/local/lib/ruby/2.1.0/uri/generic.rb:214:in `initialize': the scheme http does not accept registry part: accessibility_checker.siteimprove.com (or bad hostname?) (URI::InvalidURIError)
from /usr/local/lib/ruby/2.1.0/uri/http.rb:84:in `initialize'
from /usr/local/lib/ruby/2.1.0/uri/common.rb:214:in `new'
from /usr/local/lib/ruby/2.1.0/uri/common.rb:214:in `parse'
from /usr/local/lib/ruby/2.1.0/uri/common.rb:747:in `parse'
from /usr/local/lib/ruby/2.1.0/uri/common.rb:1232:in `URI'
from -e:1:in `<main>'
@tmichel
tmichel / constant_lookup.rb
Created July 6, 2015 14:14
Rails constant lookup WTF
# Rails autoloading constant functionality is useful until it's not.
# Every class is placed in the right file on the right path.
# in app/models/users/serializer.rb
module Users
class Serializer
#...
end
end
@tmichel
tmichel / fixtures_pg.rake
Last active August 29, 2015 14:19
Load fixtures into PostgreSQL with unprivileged user when foreign keys are active
namespace :db do
namespace :fixtures do
desc 'Load fixtures into postgres'
task :pg => [:environment, :load_config] do
require 'active_record/fixtures'
require 'postgres_foreign_keys'
module ActiveRecord::ConnectionAdapters::PostgreSQL::ReferentialIntegrity
def supports_disable_referential_integrity?
false
@tmichel
tmichel / pg_enum.rb
Created March 5, 2015 13:42
Read out enum values from Postgres with ActiveRecord
class PgEnum
attr_reader :type
def initialize(type)
@type = type.to_s
end
class << self
alias_method :for_type, :new
end
@tmichel
tmichel / Gemfile
Last active August 29, 2015 14:14
Ransack using ActiveRecord and Monogid side by side
# A sample Gemfile
source "https://rubygems.org"
gem 'activerecord'
gem 'mongoid'
gem 'sqlite3'
gem 'ransack'
@tmichel
tmichel / gocd.sh
Created October 15, 2014 13:37
cd into go packages from anywhere
# functions
function gcd ()
{
local pdir=$(go list -f '{{ .Dir }}' $1 2>/dev/null )
if [ -z "$pdir" ]; then
pdir=$(go list -f '{{ .Dir }}' ".../$1" 2>/dev/null)
fi
if [ -z "$pdir" ]; then
echo "no directory found for pkg $1"
@tmichel
tmichel / email_test.go
Created October 12, 2014 11:58
Sending and testing email in Go -- appendix
package email
import (
"net/smtp"
"testing"
)
type EmailConfig struct {
Username string
Password string