Skip to content

Instantly share code, notes, and snippets.

@davidbjourno
davidbjourno / spec.json
Last active August 18, 2022 16:11
Vega-Lite spec from Wed Aug 17 2022
{
"config": {"view": {"continuousWidth": 400, "continuousHeight": 300}},
"layer": [
{
"data": {"name": "data-1a9dea4ba8b8849e4235562cc245ac37"},
"mark": {"type": "rect", "opacity": 0.5},
"encoding": {
"color": {
"field": "ann_diff",
"legend": {"direction": "horizontal"},
@davidbjourno
davidbjourno / batch-ocr-pdfs.md
Last active March 9, 2022 16:08
Batch OCR PDFs

Batch OCR PDFs

In PDFs directory:

  1. Replace additional . in filenames with _: zmv '(*.*)(.*)' '${1//./_}$2
  2. mkdir jpg && mkdir txt
  3. mogrify -format jpg -density 200 -quality 100 -alpha off -path jpg/ -verbose *.pdf
  4. for file in jpg/*.jpg; do tesseract $file ${file%%.*}; done
  5. mv jpg/*.txt txt/

Keybase proof

I hereby claim:

  • I am davidbjourno on github.
  • I am davidcblood (https://keybase.io/davidcblood) on keybase.
  • I have a public key ASCPqRS7wa5cMJ2azRpOL_K3y9ol3xK2Hql06eCzm58T-go

To claim this, I am signing this object:

{"nodes":[{"name":"US"},{"name":"JP"},{"name":"DE"},{"name":"GB"},{"name":"FR"},{"name":"IT"},{"name":"CA"},{"name":"G7"},{"name":"CN"},{"name":"HK"},{"name":"MY"},{"name":"VN"},{"name":"IN"},{"name":"TW"},{"name":"ID"},{"name":"TR"},{"name":"TH"},{"name":"Asia Other"},{"name":"NL"},{"name":"Europe Other"},{"name":"Americas Other"},{"name":"Africa Other"},{"name":"Oceania Other"}],"links":[{"source":"CA","target":"Africa Other","value_h1_17":113.932,"value_h1_18":48.166},{"source":"CA","target":"Americas Other","value_h1_17":55.823,"value_h1_18":39.946},{"source":"CA","target":"Asia Other","value_h1_17":176.256,"value_h1_18":1266.557},{"source":"CA","target":"CN","value_h1_17":20398.059,"value_h1_18":874.396},{"source":"CA","target":"Europe Other","value_h1_17":540.634,"value_h1_18":258.634},{"source":"CA","target":"G7","value_h1_17":56895.946,"value_h1_18":57902.149},{"source":"CA","target":"HK","value_h1_17":17859.425,"value_h1_18":2566.798},{"source":"CA","target":"ID","value_h1_17":null,"value_h1_18":346.
from osgeo import ogr
# Open shapefile and count features
source = ogr.Open('building-means.shp', update=True)
layer = source.GetLayer()
features_count = layer.GetFeatureCount()
# Create new field
new_field = ogr.FieldDefn('mean_rnd', ogr.OFTReal) # Define new floating-point field
@davidbjourno
davidbjourno / hydrogen.md
Created July 4, 2018 14:22
Hydrogen multiple kernels demo

Load, join and filter with Python/pandas

import pandas as pd

df_results = pd.read_csv(
    'data/raw/EU-referendum-result-data.csv',
    index_col='Area_Code')
df_aps = pd.read_csv(
    'data/raw/2395818381.csv',
    index_col='mnemonic',
@davidbjourno
davidbjourno / gist:8d52fc61ab865edd193c296558a44961
Created June 26, 2018 19:40
Archive a site locally with wget
wget --mirror \
--convert-links \
--adjust-extension \
--page-requisites \
--wait=2 \
-U Mozilla \
https://my-url.com/
@davidbjourno
davidbjourno / countdown.js
Created April 15, 2017 11:27
Simple JavaScript countdown timer
var deadline = 1577836800000; // 00:00:00, January 1, 2020
var display = document.querySelector('#countdown');
function formatTime (milliseconds) {
var seconds = (milliseconds / 1000).toFixed(0);
var minutes = Math.floor(seconds / 60);
var hours = '';
seconds = Math.floor(seconds % 60);
@davidbjourno
davidbjourno / mov-to-gif.md
Last active January 12, 2017 14:39
Terminal commands for converting a QuickTime movie to a GIF using FFmpeg

.mov to GIF

  1. ffmpeg -i movie.mov -vf palettegen palette.png
  2. ffmpeg -i movie.mov -i palette.png -lavfi scale=1920:-1,paletteuse=bayer_scale=[0,5]:dither=bayer -r 24 movie.gif
$(document).ready(function() {
var documentHeight = $(document).height(),
windowHeight = $(window).height(),
scrollPercent;
$(window).scroll(function() {
scrollPercent = ($(window).scrollTop()) / (documentHeight - windowHeight) * 100;
$(".progress-bar").width(scrollPercent + "%");
});