Skip to content

Instantly share code, notes, and snippets.

View craigmulligan's full-sized avatar

Craig Mulligan craigmulligan

View GitHub Profile
@khalidx
khalidx / node-typescript-esm.md
Last active July 3, 2024 18:04
A Node + TypeScript + ts-node + ESM experience that works.

The experience of using Node.JS with TypeScript, ts-node, and ESM is horrible.

There are countless guides of how to integrate them, but none of them seem to work.

Here's what worked for me.

Just add the following files and run npm run dev. You'll be good to go!

package.json

@p4bl0-
p4bl0- / 00_readme.md
Last active October 12, 2023 09:09
A complete compiler for a simple language (in less than 150 LoC)

This project is a tiny compiler for a very simple language consisting of boolean expression.

The language has two constants: 1 for true and 0 for false, and 4 logic gates: ! (not), & (and), | (or), and ^ (xor).

It can also use parentheses to manage priorities.

Here is its grammar in BNF format:

expr ::= "0" | "1"

Redux WebSocket Middleware: Example

This Gist provides some code examples of how to implement WebSocket stream handling using a Redux middleware. Please be aware that this is only provided as an example and that critical things like exception handling have not been implemented.

A more complete version has been packaged, tested, and is available on GitHub as redux-websocket. This library has also been published to npm at @giantmachines/redux-websocket.

Middleware

This module represents the foundation of the middleware and implements the ideas presented above. The exported function is used during the creation of the Redux store (see the following snippet).

@leebyron
leebyron / sort-keys.js
Created January 30, 2017 21:42
Sort values by key order performance
var keys = [];
var results = [];
var keyCount = 100;
var iterations = 10000;
//generate keys 0 to <keycount>
for (var i=0; i < keyCount; i++) {
keys.push(i);
results.push({ id: i })
}
@chantastic
chantastic / on-jsx.markdown
Last active May 30, 2024 13:11
JSX, a year in

Hi Nicholas,

I saw you tweet about JSX yesterday. It seemed like the discussion devolved pretty quickly but I wanted to share our experience over the last year. I understand your concerns. I've made similar remarks about JSX. When we started using it Planning Center, I led the charge to write React without it. I don't imagine I'd have much to say that you haven't considered but, if it's helpful, here's a pattern that changed my opinion:

The idea that "React is the V in MVC" is disingenuous. It's a good pitch but, for many of us, it feels like in invitation to repeat our history of coupled views. In practice, React is the V and the C. Dan Abramov describes the division as Smart and Dumb Components. At our office, we call them stateless and container components (view-controllers if we're Flux). The idea is pretty simple: components can't

@wryun
wryun / gist:2d14b0c38b56b163a59f
Created November 25, 2014 01:08
geoalchemy2 using geojson rather than wkb/wkt (wkbelement/wktelement)
import geoalchemy2, geoalchemy2.shape
import shapely.geometry
# Could use geomet rather than pushing this through shapely.
class Geometry(geoalchemy2.Geometry):
"""Deal in GeoJSON rather than WKB/WKT"""
def result_processor(self, dialect, coltype):
super_proc = super(Geometry, self).result_processor(dialect, coltype)
def process(v):
return v and shapely.geometry.mapping(
@anthonyholmes
anthonyholmes / bootstrap-sass-mixin-cheatsheet.scss
Created October 10, 2014 08:13
Bootstrap Sass Mixin Cheatsheet
// Alerts
@include alert-variant($background, $border, $text-color);
// Background Variant
@include bg-variant($parent, $color);
// Border Radius
@include border-top-radius($radius);
@include border-right-radius($radius);
@include border-bottom-radius($radius);
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active July 27, 2024 16:01
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@jboner
jboner / latency.txt
Last active July 27, 2024 12:32
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@dfm
dfm / booboos.sh
Created May 25, 2012 05:46
Count the number of occurrences of "FIXME", "TODO", etc. in the current git repository
function count_code_booboos() {
GIT_DIR=$(git rev-parse --git-dir 2> /dev/null) || return
NOTES_PATTERN="FIXME|TODO|MAGIC"
NOTES_RES=$(echo $(ack -hi --ignore-dir="venv" --ignore-dir="build" \
"\b$NOTES_PATTERN\b" "$(dirname $GIT_DIR)" 2>/dev/null))
for NM in "FIXME" "MAGIC" "TODO"
do
num=$(echo $(echo $NOTES_RES | ack -i "\b$NM\b" | wc -l))
if [ $num != 0 ]
then