Skip to content

Instantly share code, notes, and snippets.

View waterlink's full-sized avatar

Alex Fedorov waterlink

View GitHub Profile
require "spec"
describe User do
describe "#save" do
it "saves user record to data store" do
# ...
end
end
end
Error in line 1: while requiring "./spec/compiler/codegen/special_vars_spec.cr"
Syntax error in ./spec/compiler/codegen/special_vars_spec.cr:4: unterminated macro
macro verify_special_vars(name)
^
macro create_double(name, &block)
module ::Mocks
module Doubles
class {{name.id}} < ::Mocks::BaseDouble
def ==(other)
self.same?(other)
end
def ==(other : Value)
false
# Instead of doing this:
{} of Array(Object) => Result
# Now I do this:
class Args
getter value
def initialize(@value)
randomString :: (a -> b) -> a -> a -> [b]
-- to create a random string "apply face to keyboard and roll"
randomString face keyboard roll = map face [keyboard, roll]
@waterlink
waterlink / rebase.md
Created July 6, 2015 19:56
Example rebase workflow
# Add remote origin pointing to fork, if it is not added
git remote add origin git@github.com:waterlink/contracts.ruby.git

# Add remote upstream pointing to main repo, if it is not added
git remote add upstream git@github.com:egonSchiele/contracts.ruby.git

# Fetch latest master from upstream
git fetch upstream master
# Smelly code
class Example
def do_stuff(something)
return if invalid_thing?(something)
@thing = something
end
private def invalid_thing?(thing)
# determine if thing is valid
end
@waterlink
waterlink / attr_t.c
Created August 22, 2015 17:54
Generates attr_t enum for curses
#include <curses.h>
#include <stdio.h>
#define pp(x, d) printf("% 15s = % 10lu # - %s\n", #x, x, #d);
int main() {
pp(A_NORMAL, Normal display (no highlight))
pp(A_STANDOUT, Best highlighting mode of the terminal.)
pp(A_UNDERLINE, Underlining)
pp(A_REVERSE, Reverse video)
@waterlink
waterlink / valgrind.txt
Created August 30, 2015 23:10
Valgrind output for waterlink/mysql_adapter.cr run
.where(query_hash)
finds multiple records==957== Invalid read of size 8
==957== at 0x4A0FB5: GC_generic_malloc_many (in /home/oleksii/code/github/waterlink/mysql_adapter.cr/integration_spec)
==957== by 0x4AA30E: GC_malloc_atomic (in /home/oleksii/code/github/waterlink/mysql_adapter.cr/integration_spec)
==957== by 0x4A06EC: GC_generic_or_special_malloc (in /home/oleksii/code/github/waterlink/mysql_adapter.cr/integration_spec)
==957== by 0x4A08AA: GC_realloc (in /home/oleksii/code/github/waterlink/mysql_adapter.cr/integration_spec)
==957== by 0x4142E5: __crystal_realloc (in /home/oleksii/code/github/waterlink/mysql_adapter.cr/integration_spec)
==957== by 0x42068E: *Pointer(UInt8)@Pointer(T)#realloc<Pointer(UInt8), Int32>:Pointer(UInt8) (in /home/oleksii/code/github/waterlink/mysql_adapter.cr/integration_spec)
==957== by 0x4199B6: *String::Builder#resize_to_capacity<String::Builder, Int32>:Pointer(UInt8) (in /home/oleksii/code/github/waterlink/mysql_adapter.cr/integration_spec)
==957==
ActiveRecord::Model
.new
creates person
doesn't have id
doesn't have any else field
doesn't care about non-defined fields
.fields
returns fields defined on model
#==
is equal object to object with the same fields