Skip to content

Instantly share code, notes, and snippets.

@willglynn
willglynn / indexes_for_hstore_column.sql
Created September 21, 2012 01:39
Automatic index generation for all hstore keys
CREATE OR REPLACE FUNCTION indexes_for_hstore_column(full_table_name varchar, hstore_column varchar) RETURNS SETOF varchar AS $$
DECLARE
table_oid oid;
table_name varchar;
schema_name varchar;
key varchar;
index_name varchar;
index_exists integer;
unique_keys_query varchar;
create_index_statement varchar;
@willglynn
willglynn / gemsig_proposal.md
Created October 4, 2012 02:01
.gemsig Proposal

.gemsig Proposal

RubyGems.org has little in the way of defenses against tampering. Right now, new gems could be uploaded to S3 and distributed to users worldwide without detection, and the only thing preventing this is the security of the AWS credentials presently stored on world-facing web servers. S3 Versioning is a step that could be taken immediately to reduce the severity of compromise, but a larger solution is required.

This document proposes a .gemsig file as a means of verifying that a gem has not been modified during distribution. This file would be distributed alongside the .gem files, allowing clients to verify authenticity.

Format

@willglynn
willglynn / gist:3831426
Created October 4, 2012 04:12
Rails time zones + Date.today + system time zone interaction
[1] pry(main)> [`date`, ENV['TZ'], Time.zone, Date.today.midnight, Date.yesterday.midnight]
=> ["Wed Oct 3 23:11:03 CDT 2012\n",
nil,
(GMT+00:00) UTC,
Wed, 03 Oct 2012 00:00:00 UTC +00:00,
Wed, 03 Oct 2012 00:00:00 UTC +00:00]
[2] pry(main)> ENV['TZ'] = 'UTC'
=> "UTC"
[3] pry(main)> [`date`, ENV['TZ'], Time.zone, Date.today.midnight, Date.yesterday.midnight]
@willglynn
willglynn / gist:3841654
Created October 5, 2012 18:50
Negative array indices
#include <stdio.h>
int main() {
struct {
int scalar;
int array[5];
} some_struct;
some_struct.scalar = 5;
@willglynn
willglynn / gist:3903510
Created October 17, 2012 03:14
Nesting modules within a class
class SomeClass; end
module SomeClass::NestedModule; end
puts SomeClass.class
puts SomeClass::NestedModule.class
# prints:
# Class
# Module
@willglynn
willglynn / packing.c
Created November 8, 2012 17:10
Neither #pragma pack() nor declaration order affects linker placement of globals
$ make packing
cc packing.c -o packing
$ nm packing | sort
U dyld_stub_binder
0000000100000000 T __mh_execute_header
0000000100000f50 T _main
0000000100001000 S _bar
0000000100001010 S _foo
0000000100001074 S _packed_bar
0000000100001080 S _packed_foo
@willglynn
willglynn / mission_planning.png
Created November 9, 2012 03:26
Race Into Space palettes
Race Into Space uses different palettes in different screens.
@willglynn
willglynn / gist:4072470
Created November 14, 2012 14:35
curl from S3 HTTPS
$ curl -O -v https://s3.amazonaws.com/willglynn/physfs-2.1.0-pre20121013.tgz
* About to connect() to s3.amazonaws.com port 443 (#0)
* Trying 207.171.163.13...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* connected
* Connected to s3.amazonaws.com (207.171.163.13) port 443 (#0)
* SSLv3, TLS handshake, Client hello (1):
} [data not shown]
* SSLv3, TLS handshake, Server hello (2):
@willglynn
willglynn / gist:4090893
Created November 16, 2012 21:04
Window functions for row pairs
-- PostgreSQL current
SELECT
round,
first_value(time) OVER pair AS first_time,
last_value(time) OVER pair AS last_time,
first_value(groundstatsid IS NULL) OVER pair AS first_is_standing,
last_value(groundstatsid IS NULL) OVER pair AS last_is_standing
FROM matchstats
WINDOW pair AS (PARTITION BY round ORDER BY time ROWS 1 PRECEDING);
@willglynn
willglynn / Makefile
Created November 30, 2012 03:13
Ragel for classifying log lines
line_classifier: line_classifier.o
%.c: %.rl
ragel -G2 $^ -o $@