Skip to content

Instantly share code, notes, and snippets.

git log --pretty=oneline --graph --decorate --all
ffmpeg -f lavfi -i color=c=#00000000:s=440x720 -t 16 -i input.mp4 -shortest -filter_complex "[1:v]chromakey=0x00ff00:0.2:0.2[ckout];[0:v][ckout]overlay[out]" -map "[out]" -shortest output.webm
@adav
adav / mersenne-twister.ts
Created July 3, 2020 17:44 — forked from thiloplanz/mersenne-twister.ts
A TypeScript implementation of the Mersenne Twister pseudo-random number generator
/*
* TypeScript port by Thilo Planz
*
* https://gist.github.com/thiloplanz/6abf04f957197e9e3912
*/
/*
I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace
so it's better encapsulated. Now you can have multiple random number generators
and they won't stomp all over eachother's state.
@adav
adav / gist:44ca755cf7c239623b2de47b6310c43c
Created May 17, 2020 12:57
Search nearby without postgis?
SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20;
To search by kilometers instead of miles, replace 3959 with 6371.
#!/usr/bin/env bash
# IMPORTANT
# First install and run Xcode from Mac App Store
#
# (Might as well download and setup... Affinity Designer, Trello,
# Notability, Wipr, NextDNS, The Unarchiver ...while you're there!)
#
echo "Oooh, lovely new Mac! Wish you well to use it! Time to install your 'grams..."
@adav
adav / request
Created January 3, 2019 16:43
AppSync DynamoDB Resolver List Field different Table
## Example below shows single-table batch read where the table name is "Posts" and the items in
## DynamoDB have a primary key of "id". You can read from multiple tables at once by
## specifying each table name under "tables" - e.g. "tables": {"Table1": "...", "Table2": "..."}
## Read more: https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-dynamodb-batch.html
#set($ids = [])
#foreach($stage in ${ctx.source.stages})
#set($map = {})
$util.qr($map.put("id", $util.dynamodb.toString($stage.id)))
$util.qr($ids.add($map))
@adav
adav / Rule30.scala
Created June 27, 2017 12:24
Quick and dirty go at creating the Rule 30 Cellular Automaton
object Rule30Demo extends App {
val rule30: List[Int] => Int = {
case 1 :: 1 :: 1 :: Nil => 0
case 1 :: 1 :: 0 :: Nil => 0
case 1 :: 0 :: 1 :: Nil => 0
case 1 :: 0 :: 0 :: Nil => 1
case 0 :: 1 :: 1 :: Nil => 1
case 0 :: 1 :: 0 :: Nil => 1
case 0 :: 0 :: 1 :: Nil => 1
case class Node(value: String, left: Option[Node], right: Option[Node])
val tree = Node("Sarah",
Some(Node("Fred", Some(Node("Hilary", None, None)), Some(Node("Jenny", Some(Node("James", None, None)), None)))),
None)
def checkChildrenContains(name: String, n: Node): Boolean = {
val leftContains = n.left match {
case Some(node) =>
val codes = List(
List("C","T","E","W","H","H","Y","T","K","F","X","T"), //"T","P",
List("C","T","Y","X","H","E","T","C","C","F","X","W"), //"T","P",
List("C","T","C","H","W","X","W","F","C","P","K","P"), //"T","P",
List("E","K","C","P","X","P","E","Y","K","E","W","F"), //"P","T",
List("E","P","E","H","H","H","Y","P","X","W","E","H"), //"P","T",
List("E","P","F","K","K","X","C","P","W","X","E","C"), //"P","T",
List("E","T","E","W","C","E","W","E","K","T","E","W"), //"P","T",
List("E","K","Y","E","X","C","T","F","F","K","K","W"), //"P","T",
List("E","P","E","C","Y","P","X","T","K","T","X","F"), //"P","T",
@adav
adav / FizzBuzz Scala
Last active July 13, 2016 21:31
Mindlessly reading about interviews on Hacker News and had a brainwave of how to do Fizz Buzz in a very Scala-y way :)
(1 to 100).map( i => (i % 3, i % 5) match {
case (0, 0) => "FizzBuzz"
case (0, _) => "Fizz"
case (_, 0) => "Buzz"
case _ => i
}).foreach(println)