This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$$$ | |
crystal | |
crystal run | |
crystal build | |
crystal version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Object | |
macro inherited | |
@@methods = {} of String => Proc({{@type}}, Nil) | |
macro method_added(method) | |
\{% if method.visibility == :public %} | |
%key = \{{ method.name.stringify }} | |
@@methods[%key] = ->(obj : \{{@type}}) { | |
obj.\{{ method.name }}() | |
nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################## | |
##Exercise: ModulesAndFunctions-6 | |
defmodule Chop do | |
def guess(actual, lo..hi) when (lo <= hi) and (actual in lo..hi) do | |
current = guessing(lo, hi) | |
IO.puts "Is it #{current}" | |
guess(current, actual, lo..hi) | |
end | |
defp guess(value, actual, _) when value == actual, do: IO.puts value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Must be run on an Amazon Linux AMI that matches AWS Lambda's runtime which can be found at: | |
# https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html | |
# | |
# As of Jan 10, 2019, this is: | |
# Amazon Linux AMI 2017.03.1.20170812 x86_64 HVM GP2 (ami-4fffc834) | |
# | |
# Lambda includes ImageMagick 6.7.8-9 preinstalled, so you need to prepend PATH | |
# with the folder containing these binaries in your Lambda function to ensure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def flatten(list), do: flatten(list, []) |> Enum.reverse | |
def flatten([h | t], acc) when h == [], do: flatten(t, acc) | |
def flatten([h | t], acc) when is_list(h), do: flatten(t, flatten(h, acc)) | |
def flatten([h | t], acc), do: flatten(t, [h | acc]) | |
def flatten([], acc), do: acc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "ameba" | |
source = Ameba::Source.new %( | |
class Ameba::Internals | |
getter info : Info | |
def dump | |
puts info | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "BetterTouchTool" | |
activate | |
update_trigger "EAE52DEC-26DA-40DC-8BB1-62A102FE676C" json "{\"BTTEnabled\" : %d}" | |
update_trigger "7C3BC3BC-2B93-4674-8A5F-6697FDC6E723" json "{\"BTTEnabled\" : %d}" | |
end tell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const gm = require('gm').subClass({ imageMagick: true }); | |
const root = process.env['LAMBDA_TASK_ROOT']; | |
const path = process.env['PATH']; | |
const libPath = process.env['PATH']; | |
// change the Lambda Runtime to use pre-built binary | |
process.env['PATH'] = `${root}/bin:${path}`; | |
process.env['LD_LIBRARY_PATH'] = `${root}/lib:${libPath}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "http/client" | |
require "json" | |
module GithubAPI | |
API_URL = "https://api.github.com" | |
class Repo | |
JSON.mapping( | |
name: String, | |
html_url: String, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "big/big_rational" | |
def root(n, acc = BigRational.new(2)) | |
base = ->(n : BigRational) { 2 + n.inv } | |
n.times { acc = base.call(acc) } | |
1 + acc.inv | |
end | |
puts (1..999).map { |n| root(n) }.map { |r| [r.numerator.digits.size, r.denominator.digits.size] }.count { |(n, d)| n > d } |
NewerOlder