Skip to content

Instantly share code, notes, and snippets.

View sleepingkingstudios's full-sized avatar
💭
🚀

Rob Smith sleepingkingstudios

💭
🚀
View GitHub Profile

Elixir Cheat Sheet

See the Official Guides.

Getting Started

Command Line

Start a REPL: iex

ApplicationRecord.connection.execute(
<<~SQL
CREATE TEMPORARY TABLE IF NOT EXISTS gadgets
(
id bigint NOT NULL,
name varchar(64) NOT NULL
);
CREATE TEMPORARY SEQUENCE IF NOT EXISTS gadgets_id_seq
START WITH 1
$LOAD_PATH.unshift './lib'
source_file = ARGV[0]
target_file = ARGV[1]
puts "Source: #{source_file}"
puts "Target: #{target_file}"
require 'fileutils'
class CommandParser
class OptionsParser
def initialize
@parsed = nil
@buffer = nil
@bname = nil
end # constructor
def parse tokens
self.buffer = ''
@sleepingkingstudios
sleepingkingstudios / mock_example_group.rb
Created June 20, 2017 19:11
Mock Implementations of RSpec components.
module Spec::Support
class ExampleGroup
class << self
attr_reader :description
def describe description
example_group = Class.new(self)
example_group.description = description
alias git-list-branches="git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'"
class Comparator
def initialize(actual, expected)
@actual = actual
@expected = expected
@errors = Hash.new { |hsh, key| hsh[key] = [] }
end # constructor
attr_accessor :actual, :expected, :errors
def eql?
@sleepingkingstudios
sleepingkingstudios / mixin.rb
Created August 17, 2014 23:38
Class-method inheritance.
# Implements module-based inheritance of both class- and instance-level
# methods.
module Mixin
def mixins
@mixins ||= []
end # accessor mixins
def mixins=(ary)
@mixins = ary
@sleepingkingstudios
sleepingkingstudios / .zshrc
Last active August 21, 2020 20:37
Developing For Ruby and Rails
export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"
export PGDATA="/usr/local/var/postgres"
eval "$(rbenv init - zsh)"
alias ci="bundle exec rspec && bundle exec rubocop"
alias be="bundle exec"
alias bea="bundle exec appraisal"
alias loki="bundle exec thor"
alias osd="OVERMIND_PROCFILE=Procfile.dev overmind start"