Skip to content

Instantly share code, notes, and snippets.

View getify's full-sized avatar
💭
Just coding

Kyle Simpson getify

💭
Just coding
View GitHub Profile
@getify
getify / 1.js
Last active December 8, 2023 17:51
JS vs Foi symbol count comparision: FP (partial application, pipelines, etc)
// note: this uses proposed JS syntax for pipeline operator: https://github.com/tc39/proposal-pipeline-operator
// CHARACTER STATS (code comments and their padded whitespace ignored)...
// letters, numbers (a-z A-Z 0-9): 317
// non-letters-non-whitespace: 138
// simple symbols (+ - * / . " : ( ) [ ] { } , =): 94
// compound symbols (=> ?? ?. |> %%): 15 (30 chars)
// optional semicolons: 14
// whitespace: 90
@getify
getify / 1.js
Last active December 4, 2023 20:31
JS vs Foi symbol count comparision: async IO
// note: this requires a JS library for the IO monad, for example Monio: https://github.com/getify/monio/blob/master/MONIO.md#io-monad-one-monad-to-rule-them-all
// CHARACTER STATS...
// letters, numbers, string-literal-chars (a-z A-Z 0-9 / < >): 273
// non-letters-non-whitespace: 78
// simple symbols (. ` " ( ) { } $ , =): 63
// compound symbols (=>): 4 (8 chars)
// optional semicolons: 6
// whitespace: 73
@getify
getify / gist:7325764
Last active October 26, 2023 04:04
converting between Uint8Arrays and binary-encoded strings and word-arrays (for crypto purposes, with CryptoJS and NaCL)
/*
wordArray: { words: [..], sigBytes: words.length * 4 }
*/
// assumes wordArray is Big-Endian (because it comes from CryptoJS which is all BE)
// From: https://gist.github.com/creationix/07856504cf4d5cede5f9#file-encode-js
function convertWordArrayToUint8Array(wordArray) {
var len = wordArray.words.length,
u8_array = new Uint8Array(len << 2),
offset = 0, word, i
@getify
getify / monads-and-friends.md
Created July 16, 2020 19:38
Monads and Friends...

Monads and Friends...

Over the last 24-48 hours, I've fielded quite a flurry of tweets related to a couple of threads I posted recently. Upon reflection on the feedback, especially the negative stuff, I decided to write this blog post to clarify a few things about my background on the topic, what I was trying to say, what I've done so far, and what I'm hoping to do (and learn!) in the future.

It's a bit of a lengthy read, but if you find you've got the time, I hope you'll read it.

To be clear, the feedback has been on a broad spectrum. A lot of it was actually quite positive, people thanking me and appreciating my continued efforts to try to make dev topics approachable. As a matter of fact, over the years, I've received boat loads of such positive feedback, and I'm tremendously grateful that I've had a helpful impact on so many lives.

But some of it veered decidedly the other direction. I'm deliberately not linking to it, because I don't want to either amplify or gang up on those folks. I'm offended an

@getify
getify / 1.js
Last active August 4, 2023 06:24
Converting English number sentences ("one hundred forty two point three") to numeric digits ("142.3")
convert("one hundred five"); // "105"
convert("six hundred and fifty three"); // "653"
convert("zero zero one two three"); // "123"
convert("twelve o three"); // "1203"
convert("thirteen zero nine"); // "1309"
convert("fifteen sixteen"); // "1516"
convert("fourteen ninety two"); // "1492"
convert("nineteen ten"); // "1910"
convert("twelve hundred"); // "1200"
convert("twenty three hundred"); // "2300"
@getify
getify / 1.js
Last active July 27, 2023 15:50
demonstrating how to use "nodegit" to modify and read from a local bare git repo
/*
NOTE: This code assumes a bare git repo in ./bare-git/,
which should have at least one text file in its root,
named "greetings.txt".
This code updates the contents of a "greetings.txt"
file, and creates a new file called "greetings-XXX.txt"
(with XXX being a random number). It then creates a new
commit for these changes. Finally, it reads and dumps
the new current contents of the repo, file by file.
@getify
getify / gist:2cd95b61e5105afd75f8
Last active June 12, 2023 19:06
`asyncify(..)` for ensuring callback asynchrony, from "YDKJS: Async & Performance", Chapter 2
function asyncify(fn) {
var orig_fn = fn,
intv = setTimeout( function timer(){
intv = null;
if (fn) fn();
}, 0 )
;
fn = null;
@getify
getify / 1-utils.js
Last active June 3, 2023 23:38
illustrating some "dynamic composition" usage
function flow(...fns) {
return arg => fns.reduce((res,fn) => fn(res),arg);
}
function partial(fn,initialArgs) {
return (nextArgs = []) => fn(...initialArgs,...nextArgs);
}
function pick(prop) {
return obj => obj[prop];
}
function prepend(prefix) {
@getify
getify / gist:2b53198906d320abe650
Created March 23, 2015 17:02
ES6 highlight reel
function foo(x) { x = (typeof x != "undefined") ? x : 10; .. }
function foo(x = 10) { .. }
function foo(x,y,z) { .. }; foo.apply(null,[1,2,3]);
function foo(x,y,z) { .. }; foo(...[1,2,3]);
function foo() { var args = [].slice.call(arguments); .. }
function foo(...args) { .. }
var o = { x: 2, y: 3 }, x = o.x, y = o.y, z = (typeof o.z != "undefined") ? o.z : 10;
@getify
getify / 1.html
Last active May 10, 2023 03:25
Ever noticed how vw/vh units in CSS seem to be a bit unreliable on various devices (especially mobile)? Here's my solution.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>Test Page</title>
<script>
// early compute the vw/vh units more reliably than CSS does itself
computeViewportDimensions();