Skip to content

Instantly share code, notes, and snippets.

View allain's full-sized avatar

Allain Lalonde allain

View GitHub Profile
@kohenkatz
kohenkatz / generate_ulid_text.sql
Created April 28, 2020 06:29
Postgres stuff for working with ULID
-- From https://github.com/geckoboard/pgulid/blob/d6187a00f66dca196cf5242588f87c3a7969df75/pgulid.sql
--
-- pgulid is based on OK Log's Go implementation of the ULID spec
--
-- https://github.com/oklog/ulid
-- https://github.com/ulid/spec
--
-- Copyright 2016 The Oklog Authors
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
@davidkpiano
davidkpiano / css-state-machines.md
Last active June 15, 2023 15:26
Article for creating CSS State Machines

As the number of different possible states and transitions between states in a user interface grows, managing styles and animations can quickly become complicated. Even a simple login form has many different "user flows":

https://codepen.io/davidkpiano/pen/WKvPBP

State machines are an excellent pattern for managing state transitions in user interfaces in an intuitive, declarative way. We've been using them a lot on the Keyframers as a way to simplify otherwise complex animations and user flows, like the one above.

So, what is a state machine? Sounds technical, right? It’s actually more simple and intuitive than you might think. (Don’t look at Wikipedia just yet… trust me.)

Let’s approach this from an animation perspective. Suppose you’re creating a loading animation, which can be in only one of four states at any given time:

@jbroadice
jbroadice / unpkg-npm.html
Last active September 29, 2021 15:38
unpkg.com JavaScript async module import
<!DOCTYPE html>
<html>
<head>
<title>unpkg.com dynamic import module test</title>
</head>
<body>
<script type="module">
window.module = {
set exports(module) {
window.module.modules.push(module);
@c7x43t
c7x43t / deepCopy.js
Last active May 25, 2020 19:16
Deep Copy an object very fast
// deep copy:
// String, Number, undefined, null, Set, Map, typed Array, Object, Boolean, RegExp, Date, ArrayBuffer, Node
// Functions, Properties of types: (Primitive, Symbol)
// shallow copy (by reference):
// WeakMap, WeakSet, Symbol
// increased compatibility: IE, Node
var $jscomp = $jscomp || {};
$jscomp.scope = {};
$jscomp.ASSUME_ES5 = !1;
$jscomp.defineProperty = $jscomp.ASSUME_ES5 || "function" == typeof Object.defineProperties ? Object.defineProperty : function(a, b, c) {
@tzmartin
tzmartin / m3u8-to-mp4.md
Last active May 21, 2024 12:06
m3u8 stream to mp4 using ffmpeg

1. Copy m3u8 link

Alt text

2. Run command

echo "Enter m3u8 link:";read link;echo "Enter output filename:";read filename;ffmpeg -i "$link" -bsf:a aac_adtstoasc -vcodec copy -c copy -crf 50 $filename.mp4
@jinxidoru
jinxidoru / closeable_http_server.ts
Last active January 24, 2022 19:31
Closeable http server
import * as http from 'http'
import * as _ from 'lodash'
//! In the standard implementation of http server, calling close is not guaranteed to close the
//! server. Any idle connections being kept alive by clients will stay open until their timeout
//! is reached. This is problematic for gracefully shutting down a process with an http server.
//! This function will create an http server that tracks the open connections. On close, idle
//! connections are closed and any newly idled connection is immediately closed as well. When there
//! are no more connections on the server, the 'empty' event is raised.
@chris-rock
chris-rock / crypto-stream.js
Last active October 6, 2022 18:38
Encrypt and decrypt streams
// Part of https://github.com/chris-rock/node-crypto-examples
// Nodejs encryption of buffers
var crypto = require('crypto'),
algorithm = 'aes-256-ctr',
password = 'd6F3Efeq';
var fs = require('fs');
var zlib = require('zlib');
@bhurlow
bhurlow / jpost
Last active October 30, 2021 19:05
alias so you can pipe into curl to post json
#!/bin/bash
curl -X POST -d @- $1 --header "Content-Type:application/json"
@mudge
mudge / eventemitter.js
Last active May 28, 2024 11:27
A very simple EventEmitter in pure JavaScript (suitable for both node.js and browsers).
/* Polyfill indexOf. */
var indexOf;
if (typeof Array.prototype.indexOf === 'function') {
indexOf = function (haystack, needle) {
return haystack.indexOf(needle);
};
} else {
indexOf = function (haystack, needle) {
var i = 0, length = haystack.length, idx = -1, found = false;
@douglas
douglas / update_git_repos.sh
Created October 14, 2011 15:04
Update all git repositories under a base directory
#!/bin/bash
# store the current dir
CUR_DIR=$(pwd)
# Let the person running the script know what's going on.
echo "\n\033[1mPulling in latest changes for all repositories...\033[0m\n"
# Find all git repositories and update it to the master latest revision
for i in $(find . -name ".git" | cut -c 3-); do