Skip to content

Instantly share code, notes, and snippets.

@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active June 17, 2024 15:54
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%'
@SlaunchaMan
SlaunchaMan / gist:3613715
Created September 3, 2012 21:27
Getting Image Data in iOS
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
size_t numberOfComponents = CGColorSpaceGetNumberOfComponents(colorSpace) + 1; // Add 1 for the alpha channel
size_t bitsPerComponent = 8;
size_t bytesPerPixel = (bitsPerComponent * numberOfComponents) / 8;
size_t bytesPerRow = bytesPerPixel * width;
uint8_t *rawData = (uint8_t*)calloc(width * height * numberOfComponents, sizeof(uint8_t));
CGContextRef context = CGBitmapContextCreate(rawData,
@jboner
jboner / latency.txt
Last active June 19, 2024 05:25
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@mabroor
mabroor / Procfile
Created May 25, 2012 03:19 — forked from jacobian/Procfile
Hosting Private password protected Sphinx Docs
web: gunicorn -w4 -b0.0.0.0:$PORT app:app
@rennerocha
rennerocha / README
Created May 3, 2012 20:01
Custom django-admin command that prints the CREATE TABLE SQL statements for all installed apps.
== Instructions ==
https://docs.djangoproject.com/en/1.4/howto/custom-management-commands/
Commands:
- python manage.py sqlproject
- python manage.py sqlallproject
if environment == :production
on_stylesheet_saved do |file|
# pretty logging output when making a gzipp'ed file
gz_file = Pathname.new("#{file}.gz").relative_path_from(Pathname.new(project_path))
Compass::Logger.new.record(:create, gz_file)
# This generates a file of the same name but ending in .gz
`gzip -f #{file}`
end
end
@jcroft
jcroft / layout.sass
Created March 1, 2012 04:51
How easy responsive design can be with Sass
#content-wrapper
+container
#about
// Default (smallest screens)
+column(100%)
background-color: #ccc
// Respond to other screen widths
@lukeredpath
lukeredpath / MAYBE_NULL.m
Created February 20, 2012 18:14
MAYBE_NULL
#define MAYBE_NULL(value) (value == [NSNull null] ? nil : value)
self.myProperty = MAYBE_NULL([dict objectForKey:@"might_be_null"]);
@rolo
rolo / gist:1481128
Created December 15, 2011 13:44
Install Postgres 9.1, PostGIS and create PostGIS template on Ubuntu 11.10 Oneiric Ocelot
#!/bin/bash
#
# Install Postgres 9.1, PostGIS and create PostGIS template on a clean Ubuntu 11.10 Oneiric Ocelot box
# http://wildfish.com
# add the ubuntu gis ppa
sudo apt-get -y install python-software-properties
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
@justinvoss
justinvoss / runserver-bonjour.py
Created December 9, 2011 19:27
Django + Bonjour
#!/usr/bin/env python
import sys
import subprocess
def runserver_bonjour(service_name, service_type, port):
django_process = subprocess.Popen(
['python', 'manage.py', 'runserver', '0.0.0.0:%s' % port],