Skip to content

Instantly share code, notes, and snippets.

View davidejones's full-sized avatar
🤷‍♂️
keep our code running while other packages are changing theirs

David Jones davidejones

🤷‍♂️
keep our code running while other packages are changing theirs
View GitHub Profile
@davidejones
davidejones / file.js
Last active March 5, 2018 16:08
eloquentjavascript : chapter 3
// minimum
function min(arg1, arg2) {
return (arg1 < arg2) ? arg1 : arg2;
}
console.log(min(0, 10));
console.log(min(0, -10));
// recursion
@davidejones
davidejones / file.js
Last active March 2, 2018 15:16
eloquentjavascript : chapter 2
// looping a triangle
for(var i=0; i < 8; i++) {
console.log('#'.repeat(i));
}
// fizzbuzz
for(var i=1; i < 101; i++) {
if(i % 3 == 0 && i % 5 == 0) {
console.log(i + ' FizzBuzz');
} else if(i % 3 == 0) {
@davidejones
davidejones / getlinks.py
Created November 14, 2017 18:37
Get all hrefs from a url with python3
@davidejones
davidejones / config.yaml
Created October 26, 2017 16:00
Hugo recursive partial to output navigation
languages:
en:
menu:
main:
- identifier: menu_home
name: "Home"
url: "/home/"
weight: 10
- identifier: menu_about
name: "About"
@davidejones
davidejones / extract.sh
Last active February 10, 2020 17:23
extract image from video and gif
#!/usr/bin/env bash
# image magick extract image from gif
convert Collaboration.gif[4] collaboration-static.gif
# ffmpeg extract image from timestamp
ffmpeg -ss 00:00:04 -i Collaboration.mp4 -vframes 1 collaboration.png
ffmpeg -ss 00:00:12 -i Alerts.mp4 -vframes 1 alerts.png
ffmpeg -ss 00:00:09 -i API.mp4 -vframes 1 api.png
ffmpeg -ss 00:00:07 -i APM.mp4 -vframes 1 apm.png
@davidejones
davidejones / color.sh
Last active September 12, 2017 17:18
color pick background image from hugo built html file
#!/usr/bin/env bash
# color pick the homepage
image_filename="public/$(sed -n 's/.*data-color="\([^"]*\).*/\1/p' public/index.html)"
echo "Picking color from : ${image_filename}"
if type "colorific" > /dev/null && [ -f $image_filename ]; then
picked_color=$(echo $image_filename | colorific | cut -d# -f7)
echo "Picked color : ${picked_color}"
sed -i "/^[[:space:]]*.home-blog-bg/,/}$/ s/background-color:.*/background-color: #$picked_color;}/g" public/index.html
else
@davidejones
davidejones / featured.sh
Created July 21, 2017 19:03
count hugo front matter params in a directory
@davidejones
davidejones / download_github_repo.py
Last active August 16, 2023 15:08
Downloads a github repo tar file and extracts metadata.csv files only
import os
import requests
import tarfile
def download_github_repo_tar(token, org, repo, branch, to_path):
"""
Downloads a stream tar.gz file from github of a certain organisation/branch/repo
and extracts csv files to tmp directory for parsing
@davidejones
davidejones / compress_permuation_by_index.py
Created April 13, 2017 22:13
compressing permuations by using elimination coding
import math
from functools import reduce
def bit_count(x):
""" The minimum bits needed to represent a number """
# return math.ceil(math.log(x + 1) / math.log(2))
return math.ceil(math.log2(x))
@davidejones
davidejones / Makefile
Created January 19, 2017 16:59
mingw gcc dos compile (thanks to http://nullprogram.com/blog/2014/12/09/)
CFLAGS = -std=gnu99 -Wall -Wextra -Os -nostdlib -m32 -march=i386 \
-Wno-unused-function \
-ffreestanding -fomit-frame-pointer -fwrapv -fno-strict-aliasing \
-fno-leading-underscore \
-Wl,--nmagic,-static,-Tmingw.com.ld
all:
gcc $(CFLAGS) -o hello.o hello.c
objcopy -O binary hello.o hello.com