Skip to content

Instantly share code, notes, and snippets.

View kingsleyh's full-sized avatar
😍
Coding

Kingsley Hendrickse kingsleyh

😍
Coding
View GitHub Profile
@kingsleyh
kingsleyh / a.cr
Created January 6, 2018 17:00
crystal types
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))
@kingsleyh
kingsleyh / a_my_code.cr
Created January 6, 2018 21:51
Iterator issues
p my_cursor
#<RethinkDB::Cursor:0x10bead8a0
@index=1,
@response=
#<RethinkDB::Connection::Response:0x10beb0a50
@b=nil,
@e=nil,
@n=[],
@p=nil,
@kingsleyh
kingsleyh / crystal.cr
Created January 22, 2018 12:24
crystal wierdness
base = 1
[1,2,3,4,5,6,7].each do |n|
base *= 256
p base
end
#256
#65536
#16777216
#0
@kingsleyh
kingsleyh / ensure_ascii_compatible_encoding.rb
Created January 22, 2018 18:03
ensure_ascii_compatible_encoding
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
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]
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 {
@kingsleyh
kingsleyh / ArrayExtra.mint
Last active August 31, 2018 21:14
Array.Extra
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()
}
@kingsleyh
kingsleyh / eckeycreate.c
Created December 8, 2018 23:34
create ecdsa keys
/* ------------------------------------------------------------ *
* file: eckeycreate.c *
* purpose: Example code for creating elliptic curve *
* cryptography (ECC) key pairs *
* author: 01/26/2015 Frank4DD *
* *
* gcc -o eckeycreate eckeycreate.c -lssl -lcrypto *
* ------------------------------------------------------------ */
#include <openssl/bio.h>
@kingsleyh
kingsleyh / ecdsa.cr
Created December 9, 2018 18:29
OpenSSL EC
# http://fm4dd.com/openssl/eckeycreate.htm
# https://stackoverflow.com/questions/34404427/how-do-i-check-if-an-evp-pkey-contains-a-private-key
# https://davidederosa.com/basic-blockchain-programming/elliptic-curve-keys/
lib LibSSL
fun EC_KEY_generate_key(key : LibC::Int*) : LibC::Int
fun EC_KEY_new_by_curve_name(i : LibC::Int) : LibC::Int*
fun OBJ_txt2nid(s : LibC::Char*) : LibC::Int
fun EVP_PKEY_new : LibC::Int*
fun EVP_PKEY_assign(pkey : LibC::Int*, type : LibC::Int, key : Void*) : LibC::Int
@kingsleyh
kingsleyh / Taro_spec.md
Last active September 26, 2019 09:00
Taro spec

Taro Spec

For MVP initial version:

Requirements:

  1. must support basic programming logic, math, functions, variables, collections etc
  2. must support json - encoding / decoding / traversal
  3. must have http client capability
  4. must have crypto capability, openssl