Skip to content

Instantly share code, notes, and snippets.

View lasseebert's full-sized avatar

Lasse Skindstad Ebert lasseebert

View GitHub Profile
@jodosha
jodosha / Gemfile
Created April 1, 2016 07:21
Hanami::Validations with DRY-V
source 'https://rubygems.org'
gem 'dry-validation'
@maxim
maxim / ecto_batch_stream.ex
Last active September 9, 2022 18:15
Similar to Rails `find_each`, but for Elixir's Ecto, using Stream
defmodule EctoBatchStream do
import Ecto.Query, only: [from: 1, from: 2]
@batch_size 1000
# Example:
#
# query = from u in MyApp.User, select: u.email
# stream = EctoBatchStream.stream(MyApp.Repo, query)
# stream |> Stream.take(3) |> Enum.to_list # => […]
@solnic
solnic / active-rom.rb
Created January 29, 2015 21:06
ActiveROM ;)
require 'rom-sql'
require 'virtus'
module ActiveRecord
class Base
def self.inherited(klass)
rel_class = Class.new(ROM::Relation[:sql]) {
base_name Inflecto.tableize(klass.name).to_sym
}
dataset = repository.dataset(rel_class.base_name)
@andelf
andelf / beam_decompile.erl
Created March 19, 2013 03:25
Erlang BEAM file decompile to .erl file
#!/usr/bin/env escript
% -*- mode: erlang -*-
main([BeamFile]) ->
{ok,{_,[{abstract_code,{_,AC}}]}} = beam_lib:chunks(BeamFile,[abstract_code]),
io:fwrite("~s~n", [erl_prettypr:format(erl_syntax:form_list(AC))]).
@gonzedge
gonzedge / application_controller.rb
Created January 5, 2012 02:34
Rails 3.1 - Adding custom 404 and 500 error pages
class ApplicationController < ActionController::Base
# ...
unless Rails.application.config.consider_all_requests_local
rescue_from Exception, with: lambda { |exception| render_error 500, exception }
rescue_from ActionController::RoutingError, ActionController::UnknownController, ::AbstractController::ActionNotFound, ActiveRecord::RecordNotFound, with: lambda { |exception| render_error 404, exception }
end
private
def render_error(status, exception)
@sunny
sunny / base.rb
Created December 21, 2011 09:29
Rails utility class for objets to act like ActiveRecord::Base
# encoding: utf-8
# Base class to inherit from for objects to act like ActiveRecord::Base
# without using a database. Lets you use validations, errors, forms, routes.
#
# Example:
# class Exporter < Base
# attributes_accessor :email, :data
# end
class Base
extend ActiveModel::Naming
@spicycode
spicycode / tmux.conf
Created September 20, 2011 16:43
The best and greatest tmux.conf ever
# 0 is too far from ` ;)
set -g base-index 1
# Automatically set window title
set-window-option -g automatic-rename on
set-option -g set-titles on
#set -g default-terminal screen-256color
set -g status-keys vi
set -g history-limit 10000