Skip to content

Instantly share code, notes, and snippets.

open class Vehicle {
// open fun startEngine() = println("Vroom!")
}
open class Car : Vehicle() {
// open override fun startEngine() = println("Vroom vroom!")
}
fun Vehicle.startEngine() {
println("Vroom!")
}
fun hithere(n: Int): Int {
return n
}
fun hithere(): String {
return "I'm not a number!"
}
fun main() {
val a = hithere(3)
@Jesus
Jesus / parser_example.rb
Created May 22, 2019 15:55
OptionParser doesn't support symbols as values
require 'optparse'
parser = OptionParser.new do |args|
args.on("-t", "--test VALUE") do |v|
puts "VALUE: '#{v}'"
end
end
parser.parse! ['--test', 'jibiri']
# => OK
class Fibonacci < Enumerator::Lazy
def initialize
@past_numbers = []
super(1..Float::INFINITY) do |yielder, i|
if i == 1 || i == 2
@past_numbers << i
yielder << i
else
fib_value = @past_numbers[0] + @past_numbers[1]
it "serializes an array of associated records" do
item_a = create :image_item
item_b = PreviewItem.new
item_b.preview_item_id = item_a.id
item_b.preview = item_a.preview
item_b.save!
items = [item_a, item_b]
# items = [item_a.reload, item_b.reload]
items = Marshal.load(Marshal.dump(items))
class MyInt16 < BinData::Record
def zero
0
end
uint8 :e, :check_value => lambda { value == 0 or value == 1 }
choice :int, :selection => :e do
int16be zero
int16le 1
@Jesus
Jesus / deploy.rb
Last active June 2, 2016 23:31 — forked from buntine/deploy.rb
# Clear existing task so we can replace it rather than "add" to it.
Rake::Task["deploy:compile_assets"].clear
desc "Precompile assets locally and then rsync to web servers"
task :compile_assets do
# compile assets locally
run_locally do
with rails_env: fetch(:stage) do
execute :bundle, "exec rake assets:precompile"
end
@Jesus
Jesus / config_files.rb
Last active February 21, 2021 10:44
Config. file uploader task for Capistrano 3
# lib/capistrano/tasks/config_files.cap
#
# Capistrano task to upload configuration files outside SCM
# Jesus Burgos Macia
#
# This allows us to have server's config files isolated from development ones.
# That's useful for several reasons, but the most important is that you can
# ignore files from repository.
#
# The task will upload all files found in