Skip to content

Instantly share code, notes, and snippets.

use sha2::{Digest, Sha256};
use std::path::{Path, PathBuf};
fn hash(data: String) -> [u8; 32] {
let mut hasher = Sha256::new();
hasher.update(data.as_bytes());
let r: [u8; 32] = hasher
.finalize()
.as_slice()
.try_into()
@koolquark
koolquark / Main.elm
Created July 23, 2019 04:37
Elm select list - updated to 0.19
-- See https://stackoverflow.com/questions/37376509/work-with-elm-and-select
-- Modified for Elm 0.19
import Html exposing (..)
import Html.Events exposing (on)
import Html.Attributes exposing (..)
import Json.Decode as Json
import String
import Html.Events.Extra exposing (targetValueIntParse)
import Browser exposing (sandbox)
@koolquark
koolquark / if_compact.ex
Created June 21, 2019 16:27
Elixir - One-liner if
if v, do: "v", else: "no_v"
@koolquark
koolquark / anon_call.ex
Last active June 21, 2019 16:25
Elixir - Calling anonymous function at definition itself
(fn true -> IO.puts("yes its true") end).(true)
# Example
"hello" |> ( fn msg -> IO.puts(msg) end ).()
@koolquark
koolquark / try_catch_throw.ex
Created June 21, 2019 16:04
Elixir - try catch throw example
defmodule Excep do
def ex() do
try do
throw("a")
catch
c ->
IO.inspect c # "a"
end
end
@koolquark
koolquark / match_params.ex
Created June 21, 2019 15:51
Matching two parameter values at function head
defmodule FnEx do
def m( %{ :a => a } , a ) do
IO.puts "Hello"
end
end
@koolquark
koolquark / stack_trace.ex
Created June 21, 2019 15:42
Get Current Stack Trace in Elixir
Process.info(self(), :current_stacktrace)
@koolquark
koolquark / map_match.ex
Created June 21, 2019 11:06
Elixir - Map matching at function head
defmodule MapTest do
def hmap(%{ :a => "a"} = changeset) do
IO.inspect changeset
end
end
MapTest.hmap(%{ :a => "a", :b => "B" }) # matches
MapTest.hmap(%{ :a => "A", :b => "B" }) # clause error
@koolquark
koolquark / mongodb_erlang_skip_batch_size.txt
Created December 2, 2018 10:05
mongodb erlang skip and batchsize
2> application:ensure_all_started(mongodb).
{ok,[bson,poolboy,pbkdf2,mongodb]}
3>
3> Database = <<"test">>.
<<"test">>
4> {ok, Connection} = mc_worker_api:connect ([{database, Database},{w_mode, safe}]).
{ok,<0.181.0>}
5>
5> % Drop all the docs
5> Collection = <<"test">>.
@koolquark
koolquark / postgresql.md
Last active November 21, 2018 19:10
Postgresql Create Database and User
CREATE DATABASE hello_dev;
CREATE USER devel WITH ENCRYPTED PASSWORD 'devel';
GRANT ALL PRIVILEGES ON DATABASE hello_dev TO devel;
ALTER USER devel CREATEDB;
# Also pg_hba.conf 
local all devel md5