Skip to content

Instantly share code, notes, and snippets.

@swistak35
swistak35 / Modern JS Panel.md
Created March 18, 2018 10:22
Modern JS Panel

Modern JS Panel

Description

Javascript ecosystem is changing every minute, but let's try to catch up with it at least once a year.

Questions

Ask your questions as a comments to the gist :)

@swistak35
swistak35 / Enterprise Rails.md
Last active March 17, 2018 14:49
Enterprise rails

Enterprise Rails

Description

Since ruby is mature language now, many apps we are working on are big, enterprise projects. Yeah, DDD and all, but in the end, we have to implement it. There are many frameworks/libraries which help us with that. What are your questions to authors of such tools and people working on enterprise rails apps?

Questions

Ask your questions as a comments to the gist :)

#!/bin/sh
DIR=examples/CPS
echo "=== Compiling..."
make
if [ $? -ne 0 ]
then
echo "Compilation failed."
fi
@swistak35
swistak35 / gist:e79976173b309fa0cf67
Created February 21, 2015 00:09
$... are global variables, except that no
str = "The quick fox and dog trololo"
/fox/.match(str)
def search2(str)
/and/.match(str)
puts "Inside method2: #{$&}"
end
def search(str)
/dog/.match(str)
t1 = Thread.new do
f = File.open("bar", "w")
sleep(rand(5) + 2)
f.write("test_1")
f.close
end
t2 = Thread.new do
f = File.open("bar", "w")
~% echo "" > bar
~% cat bar
~% irb
1.9.3-p547 :001 > f = File.open("bar", "w")
=> #<File:bar>
1.9.3-p547 :002 > f.write("test1")
=> 5
1.9.3-p547 :003 >
zsh: suspended irb
@swistak35
swistak35 / test_rw.ml
Last active January 2, 2016 01:19
Strange behavior of IO in Ocaml. It firstly reads value for scanf, and after that printf all stuff (even those, which it should print before scanf). test_rw2 contains even simpler example.
type ast = Cons of ast * ast
| Write
| Read
open Printf
open Scanf
let myVar = ref 0
let set_myVar x =
@swistak35
swistak35 / log
Created September 2, 2013 17:33
Enumerable#find_and_replace(cond, &block)
1.9.3p362 :002 > [1,2,3,4,5].find_and_replace(:odd?, &:to_s)
=> ["1", 2, "3", 4, "5"]
1.9.3p362 :003 > [1,2,3,4,5].find_and_replace(Proc.new(&:odd?), &:to_s)
=> ["1", 2, "3", 4, "5"]
1.9.3p362 :005 > [1,2,3,4,5].find_and_replace(->(x) { x.odd? }, &:to_s)
=> ["1", 2, "3", 4, "5"]
1.9.3p362 :006 > [1,2,3,4,5].find_and_replace(->(x) { x.odd? }) do |x|
1.9.3p362 :007 > x.to_s
1.9.3p362 :008?> end
=> ["1", 2, "3", 4, "5"]
@swistak35
swistak35 / observer.rb
Created March 20, 2013 22:35
Cutting decimals observer
def before_save(model)
model.class.columns.each do |column|
if column.type == :decimal
int_part, frac_part = model.send(column.name).to_s.split(".")
new_value = [int_part, frac_part[0...column.scale]].join(".")
model.send("#{column.name}=", new_value)
end
end
end
params[:foo] = DecimalSupport.parse_model_decimals(params[:foo], Foo)