Skip to content

Instantly share code, notes, and snippets.

@laginha87
laginha87 / not_nil_branching_failure.cr
Created May 2, 2018 18:15
not_nil_branching_failure
a = [1,2,3, nil]
if a[0]
puts a[0] + 1 # This doesn't work
end
puts a[0].not_nil! + 1 # This does though
@laginha87
laginha87 / crystal_nil_branching.cr
Created May 2, 2018 18:17
crystal nil branching
a = [1,2,3, nil]
b = a.first
if b # Create a branch of nil/not_nil
puts b + 1
else
puts "B is nil"
end
@laginha87
laginha87 / meta.rb
Created May 2, 2018 18:19
meta ruby
def method_missing(name, *args)
args.reduce {|a,b| a + b }
end
puts(sum 1,2,3,4,5)
macro method_missing(call)
{{call.args}}.reduce {|a,b| a + b }
end
puts(sum 1,2,3,4,5)
@laginha87
laginha87 / macro_example.cr
Created May 2, 2018 18:20
Macro Example cr
macro example
%a = 5
a = %a + a
end
a = 4
example
print(a) // Prints 9
function parseExtensionCommands(
extensions: Extension<any>[]
): CommandOption[] {
let options: CommandOption[] = [];
extensions.forEach(ext => {
let {
packageJSON: { contributes: { commands } = { commands: [] } }
} = ext;
if (commands) {
commands.forEach((c: Command) => {
vscode.commands.executeCommand(list.activeItems[0].command.command)
def copy(text)
IO.popen('pbcopy', 'w') {|f| f << text}
end
class Array
def to_c
copy map(&:to_s).join("\n")
end
end
puts 14.upto(18).map {|e| "Week #{e}" }
14.upto(18).map {|e| "Week #{e}" }.to_c