Skip to content

Instantly share code, notes, and snippets.

@moyix
moyix / killbutmakeitlooklikeanaccident.sh
Created February 5, 2022 22:51
Script to inject an exit(0) syscall into a running process. NB: only x86_64 for now!
#!/bin/bash
gdb -p "$1" -batch -ex 'set {short}$rip = 0x050f' -ex 'set $rax=231' -ex 'set $rdi=0' -ex 'cont'
@fantix
fantix / README.md
Last active January 22, 2024 15:16
Wire Protocol of PostgreSQL Queries in a Nutshell
@johnhw
johnhw / umap_sparse.py
Last active January 6, 2024 16:09
1 million prime UMAP layout
### JHW 2018
import numpy as np
import umap
# This code from the excellent module at:
# https://stackoverflow.com/questions/4643647/fast-prime-factorization-module
import random
@chekunkov
chekunkov / pythonstartup.py
Last active January 19, 2017 00:25
PYTHONSTARTUP file example with custom displayhook
#!/usr/bin/env python
import sys
import pprint
def displayhook_pprint(o):
"""Display hook powered by pprint.
https://www.python.org/dev/peps/pep-0217/
@dabeaz
dabeaz / calc.py
Created September 14, 2016 20:35
SLY (Sly Lex-Yacc) Example
# See: https://github.com/dabeaz/sly
from sly import Lexer, Parser
class CalcLexer(Lexer):
tokens = {
'NAME', 'NUMBER',
}
ignore = ' \t'
literals = { '=', '+', '-', '*', '/', '(', ')' }
@phobson
phobson / affine.ipynb
Last active August 26, 2016 19:18
Affine Transforms in Python
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@phobson
phobson / flow.py
Last active November 16, 2020 18:09
Arcpy vs Geopandas
import sys
import geopandas
from helpers import width, peak_flow
def flow_column_name(return_period):
return "Q{:d}".format(int(float(return_period) * 10))
from __future__ import unicode_literals
from wrapt import ObjectProxy
class Callable(ObjectProxy):
def __call__(self, *args, **kwargs):
result = self.__wrapped__
if 'upper' in kwargs:
result = result.upper()
return result
@snorfalorpagus
snorfalorpagus / split.py
Created January 23, 2016 10:02
Shapely ST_Split
from shapely.geometry import Point, LineString, Polygon, GeometryCollection, MultiLineString
from shapely.ops import polygonize, unary_union, nearest_points
from shapely.wkt import loads as load_wkt
def split_polygon_line(polygon, line):
"""Split a Polygon with a LineString"""
assert(isinstance(polygon, Polygon))
assert(isinstance(line, LineString))
boundary = polygon.boundary
union = boundary.union(line)
#!/bin/bash
#
# tile_georef.sh
#
# Grab an mapbox ZYX tile and save as a geotiff with geoferencing
# tile_georef.sh 13 4168 3197 mapbox.satellite output.tif
#
set -u