Skip to content

Instantly share code, notes, and snippets.

View usametov's full-sized avatar

Ulan Sametov usametov

  • Asta Nova Enterprise Solutions
View GitHub Profile
@usametov
usametov / merkle.tree.clj
Created May 14, 2021 21:24 — forked from maxcountryman/merkle.tree.clj
A Clojure Merkle tree utilizing SHA-256.
(ns merkle.tree
(:import [java.security MessageDigest]))
(defn sha-256-digest [bs]
(.digest
(doto (MessageDigest/getInstance "SHA-256")
(.update bs))))
(def double-sha-256 (comp sha-256-digest sha-256-digest))
;; # Maria for Experts
;; This is a short tour of abstractions we've made in the process of building Maria,
;; which are also available while using the system. It is meant for people with experience using
;; functional programming languages who already know how to evaluate forms in Maria.
;; If you're a beginner to Maria or to programming in general, I recommend starting [here](https://www.maria.cloud/intro).
;; (For the impatient, Command-Enter — Control-Enter on a PC — within a code block with evaluate the code before the cursor.)
;; ## Notebook interface
@usametov
usametov / pattern-matching.cs
Created April 20, 2021 17:08
cool pattern matching in modern C#
public static T ExhaustiveExample<T>(IEnumerable<T> sequence) =>
sequence switch
{
System.Array { Length : 0 } => default(T),
System.Array { Length : 1} array => (T)array.GetValue(0),
System.Array {Length : 2} array => (T)array.GetValue(1),
System.Array array => (T)array.GetValue(2),
IEnumerable<T> list
when !list.Any() => default(T),
IEnumerable<T> list
@usametov
usametov / csharp-nullable-types.cs
Created April 20, 2021 15:34
CSharp nullable types notes
// using the same syntax as for value types
string nonNullable = null; // compiler warning
string? nullable = null;
// here is breaking change in a new version of the language,
// the nullable reference types is the only feature of C# 8 that isn’t enabled by default
//look: before C# 8
string nullableString;
@usametov
usametov / Docker
Last active April 16, 2021 21:26 — forked from mitchwongho/Docker
Docker 'run' command to start an interactive BaSH session
# Assuming an Ubuntu Docker image
$ docker run -it <image> /bin/bash
# without the /bin/ part
docker run -it ubuntu bash
# nothing else but bash...
docker run -it bash
#if image has a defined ENTRYPOINT. For these cases use:
docker run -it --entrypoint /bin/bash <image>
@usametov
usametov / instaparse.clj
Created April 4, 2021 01:35 — forked from taylorwood/instaparse.clj
Clojure Instaparse examples
;; "human" date/time format parsing
(def human-time-parser
(insta/parser
"S = H (':' M)? ' '? P? (' ' Z)?
H = #'[1-9]' | #'1[0-2]'
M = #'0[0-9]' | #'[1-5][0-9]'
P = AM | PM
AM = 'A' 'M'?
PM = 'P' 'M'?
@usametov
usametov / topics-search.txt
Created February 16, 2021 01:50
how to search github.com for multiple topics
Github.com ui .currently does not natively supoport search for multiple topic tags as of now. However their api allows you to query multiple tags. Below is a simple example to query github.com with ecs and go topic tags.
curl -H "Accept: application/vnd.github.mercy-preview+json" \
https://api.github.com/search/repositories?q=topic:ecs+topic:go
Response from the github can be rather verbose so lets filter only relavant info such repo url and description.
curl -H "Accept: application/vnd.github.mercy-preview+json" \
https://api.github.com/search/repositories\?q\=topic:ecs+topic:go | jq '.items[] | {url:.url, description:.description}'
(ns talk
(:require [overtone.core :refer :all]
[clojure.java.io :as io]
[clj-http.client :as http]
[clojure.test :as test]))
(def talk
{:title "Sequencing dance music with Clojure"
:author "Piotr Jagielski"
:company {:name "TouK" :what "Software house" :from "Warsaw, Poland"}
(ns talk
(:require [overtone.core :refer :all]
[clojure.java.io :as io]
[clj-http.client :as http]
[clojure.test :as test]))
(def talk
{:title "Sequencing dance music with Clojure"
:author "Piotr Jagielski"
:company {:name "TouK" :what "Software house" :from "Warsaw, Poland"}
@usametov
usametov / vidwiz.clj
Created February 3, 2021 22:47 — forked from adam-james-v/vidwiz.clj
Clojure/babashka script to help automate some of my video editing pipeline
#!/usr/bin/env bb
(ns vidwiz.main
"This is a prototype script for automating a portion of my video editing using ffmpeg."
(:require [clojure.java.shell :refer [sh]]
[clojure.string :as st]))
;; util
(defn get-extension
[fname]