Skip to content

Instantly share code, notes, and snippets.

import proj4 from 'proj4'
proj4.defs([
[
'CCCAMP2019',
'+proj=tmerc +ellps=GRS80 +lat_0=0 +lon_0=15 +k=0.9996 +x_0=114350 +y_0=-5877600 +units=m +no_defs',
],
])
type CoordsLike = [number, number] | maplibregl.LngLat
@russss
russss / deskew.py
Created September 10, 2018 12:05
Automatic scanned image rotation/deskew with OpenCV
import cv2
import numpy as np
def deskew(im, max_skew=10):
height, width = im.shape
# Create a grayscale image and denoise it
im_gs = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
im_gs = cv2.fastNlMeansDenoising(im_gs, h=3)
@russss
russss / grab_mjpeg_frame.py
Created August 13, 2011 12:26
Grab a single frame from an MJPEG stream
#!/usr/bin/env python
import socket
import sys
if len(sys.argv) != 3:
print "Usage: %s host:port destfile.jpg" % sys.argv[0]
sys.exit(1)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host, port = sys.argv[1].split(':')
@russss
russss / paypal2ofx.py
Created August 7, 2011 22:15
Convert a paypal CSV export to an OFX file
import csv
import sys
from collections import namedtuple
rows = csv.reader(sys.stdin)
fields = [field.strip().lower().replace(' ', '_').replace('/', '_')
for field in rows.next() if field.strip() != '']
PaypalRecord = namedtuple('PaypalRecord', fields)
@russss
russss / graphite-jenkins.py
Created June 7, 2012 10:46
Quick script to send Jenkins successful build durations to Graphite
#!/usr/bin/env python
""" Sends Jenkins build duration statistics to Graphite. """
import requests
import json
from graphite import Graphite # This is our closed-source library but you get the idea.
JENKINS_URL='http://jenkins'
GRAPHITE_HOST='10.x.x.x'
GRAPHITE_PREFIX='jenkins.main.build_time.'
# coding=utf-8
from __future__ import division, absolute_import, print_function, unicode_literals
import csv
import boto3
from zipfile import ZipFile
import io
import tempfile
from decimal import Decimal
import datetime
from collections import defaultdict
@russss
russss / ukpolitics-code-of-conduct.md
Last active May 5, 2016 22:16
##ukpolitics Code of Conduct
  • Sexist, homophobic, racist, transphobic, ableist, sexist or otherwise offensive remarks are not allowed. (Swearing is allowed, but never targeting another user, and never in a hateful or sexually explicit manner.)
  • Remarks that make any of the ops go “Hm, that’s inappropriate”, whether on the above list or not: also not allowed.
  • You get a warning.
  • If the warning is not taken seriously, you might get a second sterner warning in PM, if you’re lucky, and the op is feeling generous, and this is the first time. But don’t count on that.
  • If the warning is unheeded, you get kicked.
  • If you come back and continue to make trouble, you get banned.
  • If you contact the offended party, and are truly apologetic, and it was the first offense, and the op who banned you feels it’s appropriate, then you may get un-banned.
  • If an op bans you, I’m definitely not going to unban you unless they agree it’s a good idea.
  • If an op bans someone, and you think it was unjustified, take it up with that op, or with a differe
#!/usr/bin/ruby
# Download NASA MODIS imagery and use it as a desktop background.
# You'll need ImageMagick installed for this to work.
require 'date'
require 'net/http'
# Screen width/height
X = 2580
Y = 1024
# Listen to a CurrentCost monitor on the serial port and forward data to Graphite
import serial
import socket
import time
from lxml import etree
ser = serial.Serial('/dev/ttyUSB0', 57600)
def send_metric(value):
sock = socket.socket()
@russss
russss / check_rabbitmq_messages
Created September 1, 2011 15:21
Nagios/Icinga plugin to get the number of un-acked messages in a number of RabbitMQ queues
#!/usr/bin/env python
# https://gist.github.com/gists/1186406
import httplib2, json, re, sys
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-w", "--warning", dest="warning", type="int",
default="50", help="warning threshold")
parser.add_option("-c", "--critical", dest="critical", type="int",
default="100", help="critical threshold")