Skip to content

Instantly share code, notes, and snippets.

Avatar

Hans Roman snahor

  • Wakanda
View GitHub Profile
View foo.sml
fun help () = print "Run me as: \n\tpoly -q --use foo.sml --eval 'val _ = main ()'\n"
fun main () = (TextIO.output (TextIO.stdErr, "ZOMG!"); OS.Process.exit OS.Process.success)
View derp.js
// count occurrences of the same combination of characters in an array of strings
// example:
// > console.log(count(['ab', 'ba']))
// [2]
const xs = [ 'aba', 'aab', 'ccc', 'ddc', 'dcd', 'baa', 'dds', 'sdd', 'dcd', 'xyz' ];
const count = xs => {
const map = xs.reduce((acc, x) => {
const key = Array.from(new Set(x)).sort().join('');
return {
View concurrency-8.go
package main
import (
"fmt"
"sort"
"golang.org/x/tour/tree"
)
// Walk walks the tree t sending all values
View max_difference.py
def max_difference(xs):
max = min = xs[0]
d = -1
for x in xs[1:]:
if min > x:
min = max = x
continue
if x > max:
max = x
if max - min > d:
View fizzbuzz.sml
fun fizzbuzz' n =
case (n mod 5 = 0, n mod 3 = 0) of
(true, true) => "FizzBuzz"
| (true, false) => "Buzz"
| (false, true) => "Fizz"
| _ => Int.toString n
fun fizzbuzz n =
let
fun loop m =
@snahor
snahor / derp.hs
Last active Oct 18, 2016
F#'s pipe forward in Haskell
View derp.hs
(|>) :: a -> (a -> b) -> b
x |> f = f x
[1..6] |> sum
inc = (+) 1
[1..5] |> map inc |> sum
View temp.js
const findLastRowWithValue = (sheet) => {
const { decode_cell } = XLSX.utils;
const { r } = decode_cell(sheet['!ref'].split(':')[1]);
const isEmpty = (x) => sheet[`A${ x }`].v === undefined;
let start = 1;
let end = r + 1;
let pivot = Math.round((end - start) / 2);
if (pivot === 0) {
View foo.jsx
{
do {
if (!this.isQuotePublished()) {
<div>
<Dialog ref="modalDeleteQuoteDraft" type="modal">
<DialogOverlay>
<DialogHeader>
<DialogTitle>{ t('QUOTE_DRAFT_DELETE') }</DialogTitle>
</DialogHeader>
<p style={ { padding: 20 } }>
View .vb
Function nameList(ParamArray xs() As Variant) As String
For i = LBound(xs) To UBound(xs)
For Each x In xs(i).Cells
If x.value <> "" Then
If nameList <> "" Then
nameList = nameList & ", "
End If
nameList = nameList & x.value
End If
Next x
View retry.js
function* fib() {
let a = 0;
let b = 1;
while (true) {
[a, b] = [b, a + b];
yield a;
}
}
const sleep = async (n) => await (new Promise(r => setTimeout(r, n)));