Skip to content

Instantly share code, notes, and snippets.

@roine
roine / sublime merge and husky.md
Created September 29, 2024 06:29
Sublime merge and husky

Sublime merge runs in its own context and so when running husky pre-commit script it might not be able to find a command (eg: npx). The solution is to update the PATH with your bin within the husky script.

Open .husky/_/h and upadte the PATH.

PATH="/Users/jon/.n/bin:$PATH"
@roine
roine / sublime merge and intellij.md
Last active September 29, 2024 05:50
Opening Intellij from sublime merge

In this example I'll setup PHPStorm to open from sublime merge.

Editor Path: /Applications/PhpStorm.app/Contents/MacOS/phpstorm
Editor argument format: --line ${line} ${file}

@roine
roine / invariant.js
Created May 22, 2024 01:18
Custom version of invariant, removes the invariant frame from the call stack
function invariant(condition, message, a, b, c, d, e, f) {
if (!condition) {
var error;
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error(
message.replace(/%s/g, function () {
return args[argIndex++];
})
@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)