This file contains hidden or 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
module Array.Extra { | |
/* | |
Map over a nested array and then flatten: | |
[[1,2],[1,5]] | |
Array.Extra.flatMap((a : Array(Number) : Array(Number) => { [Array.max(n)] }) == [2,5] | |
*/ | |
fun flatMap (func : Function(a, Array(b)), array : Array(a)) : Array(b) { | |
Array.map(func, array) | |
|> Array.Extra.concat() | |
} |
This file contains hidden or 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
component Slider { | |
property onChange : Function(Number, Void) = (value : Number) : Void => { void } | |
property disabled : Bool = false | |
property max : Number = 100 | |
property value : Number = 0 | |
property step : Number = 1 | |
property min : Number = 0 | |
state sliderPos : String = Number.toString(value) | |
style rangeSlider { |
This file contains hidden or 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 "ssh2" | |
SSH2::Session.open("localhost", 22) do |session| | |
session.login("test", "password") | |
session.open_session do |ch| | |
ch.request_pty("vt100") | |
ch.shell | |
session.blocking = false | |
buf_space = uninitialized UInt8[1024] |
This file contains hidden or 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 ensure_ascii_compatible_encoding(string, options = nil) | |
if string.encoding.ascii_compatible? | |
string | |
else | |
string.encode(Encoding::UTF_8, options || {:invalid => :replace, :undef => :replace}) | |
end | |
end |
This file contains hidden or 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
base = 1 | |
[1,2,3,4,5,6,7].each do |n| | |
base *= 256 | |
p base | |
end | |
#256 | |
#65536 | |
#16777216 | |
#0 |
This file contains hidden or 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
p my_cursor | |
#<RethinkDB::Cursor:0x10bead8a0 | |
@index=1, | |
@response= | |
#<RethinkDB::Connection::Response:0x10beb0a50 | |
@b=nil, | |
@e=nil, | |
@n=[], | |
@p=nil, |
This file contains hidden or 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
result = repo.user.findByEmail(user.value["email"]) | |
p typeof(result.value) #(Iterator::Stop | RethinkDB::QueryResult | String) | |
p result.value.is_a?(RethinkDB::QueryResult) #true | |
result.should be_a(DB::Success(RethinkDB::QueryResult)) # fails with error below | |
Failures: | |
1) Repository Repository::User should find a user by email | |
Failure/Error: result.should be_a(DB::Success(RethinkDB::QueryResult)) |
This file contains hidden or 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 onParams(context, klass : T, &block) forall T | |
result = klass.parse(contextToJson(context)) | |
p typeof(result) | |
if result.is_a?(T) | |
yield result | |
else | |
HTTPCodes.notFound(context, {message: result}) | |
end | |
end |
This file contains hidden or 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 isLoggedIn(context, repo) | |
sessionId = context.session.string?("userId") | |
if sessionId | |
user = repo.findUserByUserId(sessionId) | |
case user | |
when DB::Success | |
groupId = user.value["activeChannel"].as_h.fetch("groupId", "") | |
channelId = user.value["activeChannel"].as_h.fetch("channelId", "") |
This file contains hidden or 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
module Main exposing (..) | |
import Html exposing (Html, button, div, input, p, program, text) | |
import Html.Attributes exposing (placeholder, type_) | |
import Html.Events exposing (onClick, onInput) | |
-- MODEL | |