Skip to content

Instantly share code, notes, and snippets.

View dschep's full-sized avatar

Daniel Schep dschep

View GitHub Profile
@dschep
dschep / py
Last active September 13, 2022 18:55
Shortcut for commandline python use
#!/usr/bin/env python3
"""
More convinient than `python -c`.
Automatically imports python modules and prints the repr of the last statement.
for example:
`py 'json.load(sys.stdin)'`
instead of
`python -c 'import json,stdin;print(repr(json.load(sys.stdin)))`
@rgbkrk
rgbkrk / hubdecrypt.sh
Last active April 6, 2022 02:55
Encrypt a (short) file using someone's public key from github
#!/usr/bin/env bash
# HubCrypt
# ========
#
# Decrypt a file encrypted using hubencrypt (ok, it's just openssl + rsautl +
# your SSH keys). It needs the private key that matches your last public key
# listed at github.com/<user>.keys
#
@shovon
shovon / increase_swap.sh
Created April 10, 2015 15:18
Increasing swap size. Only tested on the ubuntu/trusty64 Vagrant box. CREDIT GOES TO ---> http://jeqo.github.io/blog/devops/vagrant-quickstart/
#!/bin/sh
# size of swapfile in megabytes
swapsize=8000
# does the swap file already exist?
grep -q "swapfile" /etc/fstab
# if not then create it
if [ $? -ne 0 ]; then
@dschep
dschep / ST_LineChunk.sql
Last active January 10, 2021 02:43
Line chunking implementations for PostGIS
CREATE OR REPLACE FUNCTION ST_LineChunk(geom geometry, max_length float8) RETURNS SETOF geometry AS $$
WITH
points AS (
SELECT generate_series(0, CEIL(ST_Length(geom) / max_length)::int)
/ CEIL(ST_Length(geom) / max_length) "end"
),
line_points AS (SELECT LAG("end", 1) OVER (ORDER BY "end") "start", "end" FROM points)
SELECT ST_LineSubstring(geom, "start", "end")
FROM line_points
WHERE "start" IS NOT NULL AND "start" <> 1
@dschep
dschep / ST_TileEnvelope.sql
Last active January 9, 2021 18:41
ST_TileEnvelope backport
-- ported from https://github.com/pramsey/minimal-mvt/blob/58f3e695a305f42024dcf0ba395590bf39b0b573/minimal-mvt.py#L63-L81
CREATE OR REPLACE FUNCTION ST_TileEnvelope(tileZoom integer, tileX integer, tileY integer) RETURNS geometry AS $$
-- Width of world in EPSG:3857
DECLARE worldMercMax float = 20037508.3427892;
DECLARE worldMercMin float = -1 * worldMercMax;
DECLARE worldMercSize float = worldMercMax - worldMercMin;
-- Width in tiles
DECLARE worldTileSize float = power(2, tileZoom);
-- Tile width in EPSG:3857
DECLARE tileMercSize float = worldMercSize / worldTileSize;
import { useState } from "react";
const useLocalStorageState = (storageKey, defaultValue) => {
const [value, setValue] = useState(
JSON.parse(localStorage.getItem(storageKey) || "null") || defaultValue
);
const wrappedSetValue = (newValue) => {
localStorage.setItem(storageKey, JSON.stringify(newValue));
setValue(newValue);
@rsvp
rsvp / netspeed.sh
Last active May 13, 2020 15:08
netspeed.sh : check download speed rate via command line | Linux bash script
#!/usr/bin/env bash
# bash 4.1.5(1) Linux Ubuntu 10.04 Date : 2013-07-11
#
# _______________| netspeed : check download speed via command line.
#
# Usage: netspeed [tokyo, london, usw, use, east, west, URL]
# ^default U.S. west coast.
# [ -speed_KB/sec ]
# ^negation activates the Mbps converter.
#
@dschep
dschep / swc
Created March 24, 2016 01:29
Streaming version of wc -l
#!/bin/bash
exec awk '{printf "\r%lu", NR}'
javascript: function runDownloadThing(howManyToDownload) {
if (!howManyToDownload) {
howManyToDownload = 3;
}
if (window['downloadSome']) {
window.downloadSome();
return;
}
var iter = $('div.download a.a:not([download])').toArray();
iter = iter.concat($('div.row a[download]').toArray());
@dschep
dschep / fix-apple-kbd.sh
Created November 25, 2015 15:23
Swap Alt & Meta and default to Fkeys not media keys
#!/bin/bash
echo 2 | sudo tee /sys/module/hid_apple/parameters/fnmode
echo 1 | sudo tee /sys/module/hid_apple/parameters/swap_opt_cmd