Skip to content

Instantly share code, notes, and snippets.

@dgillis
dgillis / index.html
Created February 13, 2018 03:24 — forked from hubgit/index.html
Render the text of a PDF with PDF.js
<!doctype html>
<meta charset="utf-8">
<title>Render the text of a PDF with PDF.js</title>
<style>
.page-container {
box-shadow: 0 1px 3px #444;
position: relative;
font-size: 1px;
line-height: 1;
@dgillis
dgillis / gist:4bc81ee9f247679460095ed1903a285a
Created July 4, 2016 20:06 — forked from philipn/gist:5274197
Running Ubuntu on a Macbook Air

Running Ubuntu on a Macbook Air

You don't have to be a slave to OS X! Here's a guide to a sane dual-booting setup with Ubuntu 12.10 on your shiny MacBook Air. This is written and tested for a MacBook Air 5,2 (Mid 2012), but likely works the same with any modern Macbook.

Install according to instructions at this URL:

@dgillis
dgillis / ex.sql
Created September 11, 2015 16:03
create table tbl (id serial primary key, obj jsonb);
select json_populate_record(null::tbl, '{"id": 1, "obj": {"id": 8}}');
-- ERROR: invalid input syntax for integer: "{"id": 8"

Set up Django, nginx and uwsgi

Steps with explanations to set up a server using:

  • virtualenv
  • Django
  • nginx
  • uwsgi
class VARTYPE(UserDefinedType):
def get_col_spec(self):
return 'VARTYPE'
def bind_processor(self, dialect):
"""Convert from Python type to DB type."""
return _to_vartype_input
def result_processor(self, dialect, coltype):
CREATE TABLE IF NOT EXISTS "collection" (
"id" bigserial NOT NULL PRIMARY KEY,
"label" varchar(200) NOT NULL
);
CREATE TABLE IF NOT EXISTS "unit" (
"id" bigserial NOT NULL PRIMARY KEY,
"collection_id" bigint NOT NULL REFERENCES "collection" ("id") DEFERRABLE INITIALLY DEFERRED,
"label" varchar(200) NOT NULL,
"display_label" varchar(200) NOT NULL,
/* vartype.h */
#define VT_INT 0
#define VT_FLOAT 1
#define VT_BOOL 2
#define VT_STRING 3
#define VT_DATE 4
#define VT_TIMESTAMP 5
/* vartype.c */
const char *VT_TYPE_NAMES[] = {
CREATE TABLE IF NOT EXISTS example (
id serial NOT NULL PRIMARY KEY,
json_text text
);
INSERT INTO example (json_text) VALUES ('100'), ('99');
/*
I'd like JSON numbers to be sorted as numbers. So '100' > '99'. But since they're text: