Skip to content

Instantly share code, notes, and snippets.

View walkermatt's full-sized avatar
💭
Drinking tea

Matt Walker walkermatt

💭
Drinking tea
View GitHub Profile
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active August 13, 2025 15:56
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@edsu
edsu / unshorten_tweet_urls.py
Created January 18, 2013 18:19
get unshortened URLs out of large batches of Twitter JSON data
#!/usr/bin/env python
"""
Feed this program line-oriented JSON tweet data (as received from the API)
on STDIN and get unshortened URLs mentioned in the tweets on STDOUT.
This module will look up multiple urls at once using the multiprocessing
library. Change CONCURRENCY to have more or less processes, defaults to 10.
"""
@miguelgrinberg
miguelgrinberg / rest-server.py
Last active July 30, 2025 09:09
The code from my article on building RESTful web services with Python and the Flask microframework. See the article here: http://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask
#!flask/bin/python
from flask import Flask, jsonify, abort, request, make_response, url_for
from flask_httpauth import HTTPBasicAuth
app = Flask(__name__, static_url_path = "")
auth = HTTPBasicAuth()
@auth.get_password
def get_password(username):
if username == 'miguel':
@mjhea0
mjhea0 / 1 - sql_interview_questions.md
Last active June 22, 2024 09:44
Jitbit's SQL interview questions
@Zverik
Zverik / SingleTile.js
Last active July 4, 2018 12:41
A layer for single-tile WMS layers. Displays a layer as a big picture, updates it on pan and zoom. This is a hack, made for an internal project; still waiting for https://github.com/Leaflet/Leaflet/issues/558 to be solved nicely. Example: L.singleTile('http://irs.gis-lab.info/').setParams({layers: 'landsat'}).addTo(map); (won't work, because tha…
/*
* L.SingleTile uses L.ImageOverlay to display a single-tile WMS layer.
* url parameter must accept WMS-style width, height and bbox.
*/
L.SingleTile = L.ImageOverlay.extend({
defaultWmsParams: {
service: 'WMS',
request: 'GetMap',
version: '1.1.1',
@georgevreilly
georgevreilly / sessionrecorder.py
Last active June 15, 2023 14:45
WSGI Middleware to record Request and Response data
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
WSGI middleware to record requests and responses.
"""
from __future__ import print_function, unicode_literals
import logging
@fnicollet
fnicollet / gist:5764080
Created June 12, 2013 09:50
Single tile WMS layer for Leaflet. Kind of hacked on top of ImageOverlay, a new image is requested when the viewport is changed. Supports reprojection through proj4-leaflet There are actually 2 images (_image and _imageSwap) because if you use the _image from ImageOverlay, and set his "src" attribute to the new WMS bbox, your layer will disappea…
goog.provide('L.SingleTileWMSLayer');
goog.require('L.Map');
L.SingleTileWMSLayer = L.ImageOverlay.extend({
defaultWmsParams: {
service: 'WMS',
request: 'GetMap',
version: '1.1.1',
@jpetitcolas
jpetitcolas / gist:5967887
Created July 10, 2013 16:37
Encode/decode a base64 encoded string in PostGreSQL
-- Decoding
SELECT CONVERT_FROM(DECODE(field, 'BASE64'), 'UTF-8') FROM table;
-- Encoding
SELECT ENCODE(CONVERT_TO(field, 'UTF-8'), 'base64') FROM table;
@AdoHaha
AdoHaha / test_throttle.py
Last active May 7, 2016 06:17
A throttle function decorator in Python similar to the one in underscore.js, inspired by debounce decorator from: https://gist.github.com/walkermatt/2871026
#!/usr/bin/python
import unittest
import time
from throttle import throttle
class TestThrottle(unittest.TestCase):
@throttle(1)
def increment(self):
@agness
agness / custom_logging.py
Created August 22, 2013 17:32
Logging in Python with Tornado's pretty print formatter and routing all messages with INFO level and above to STDOUT, and all messages below to STDERR.
#!/usr/bin/env python
import sys
import logging
import tornado.log
# For pretty log messages, if available
try:
import curses
except ImportError:
curses = None