Skip to content

Instantly share code, notes, and snippets.

@roine
roine / light-tree.json
Created March 4, 2024 11:58
light tree
{
"val": 1,
"left": {
"val": 2,
"left": {
"val": 4,
"left": null,
"right": null
},
"right": {
@roine
roine / canva-tech-interview.js
Created February 13, 2024 05:58
Canva tech interview - no job offer
/**
* The input string can contain any of: -, *, ^ alongside any valid numerical number (including decimals).
* Standard operator precedence applies with ^ being higher than * higher than - .
An example program input might be 5 * 4 - 3 - 5 ^ 3 which should output -108
For the purposes of this program you can assume that negative numbers and parenthesis are not allowed. Additionally,
we are not concerned about floating point precision or numbers that would exceed the float type size.
While some languages have built in support for eval-ing expressions, we ask you don’t use these features when designing
a solution.
*/
@roine
roine / helpers.js
Created September 7, 2023 05:58
helpers to build user scripts
/**
* Observe dom mutation and return a promise with the element when element is either present or appear on the page
*/
function waitForElm(selector) {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
@roine
roine / NumberRange.ts
Last active October 11, 2021 00:37
Range of numbers
type NumberRange<Min extends number, Max extends number> = _Range<Max, _Range1<Min,[Min]>>;
type _Range1<Min extends number, Acc extends unknown[]> = Acc['length'] extends Min ? Acc : _Range1<Min, [Min, ...Acc]>
type _Range<Max extends number, Range extends unknown[]> = Range['length'] extends Max
? Range['length']
: Range['length'] | _Range<Max, [Max, ...Range]>;
type FiveTo7 = NumberRange<5,7>
// 5 | 6 | 7
type OneTo7 = NumberRange<1,7>
module Debug.Extra exposing (viewModel)
import Html exposing (Html, p, pre, text)
import Html.Attributes exposing (style)
quote =
"\""
@roine
roine / Sample.elm
Last active September 23, 2018 10:27
Efficient (but less readable) checking if Leap Year. sample: https://ellie-app.com/3qN2Njbf2VWa1, source: https://stackoverflow.com/a/11595914/966187
isLeapYear : Int -> Bool
isLeapYear year =
Bitwise.and year 3 == 0 && (not (modBy year 25 == 0) || Bitwise.and year 15 == 0)
@roine
roine / 0_README.md
Last active April 8, 2021 20:35
Bare minimum for Elm 0.19

From 0.19 Elm introduced 4 ways to boot an app:

  1. sandbox (no outside interaction)
  2. element (simple outside interaction - side effect, flags, subscriptions)
  3. document (same as above but with title tag control)
  4. application (whole SPA features)

Keybase proof

I hereby claim:

  • I am roine on github.
  • I am roine (https://keybase.io/roine) on keybase.
  • I have a public key ASDvAb8MA0QlE3KRNLrTECoLQHkKG0_g6V6zalgXio_UvAo

To claim this, I am signing this object:

@roine
roine / gist:e40afdd44d7fa421900b81a5917f001c
Created February 28, 2017 17:54
json decode without mapN
https://ellie-app.com/wmXvyWVYqza1/0