This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)))` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
exec awk '{printf "\r%lu", NR}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo 2 | sudo tee /sys/module/hid_apple/parameters/fnmode | |
echo 1 | sudo tee /sys/module/hid_apple/parameters/swap_opt_cmd |