Skip to content

Instantly share code, notes, and snippets.

View gregorynicholas's full-sized avatar
💀
alter.

gregory nicholas gregorynicholas

💀
alter.
View GitHub Profile
@gregorynicholas
gregorynicholas / rasterize.js
Created June 19, 2018 18:43 — forked from FiloSottile/rasterize.js
PhantomJS rasterize.js with "Retina" output
var page = require('webpage').create(),
address, output, size;
if (phantom.args.length < 2 || phantom.args.length > 3) {
console.log('Usage: rasterize.js URL filename');
phantom.exit();
} else {
address = phantom.args[0];
output = phantom.args[1];
page.viewportSize = { width: 1280, height: 1024 };
@gregorynicholas
gregorynicholas / export-google-docs-to-restructured-text.js
Created June 19, 2018 18:43 — forked from simonw/export-google-docs-to-restructured-text.js
Google Apps script to convert a Google Docs document into reStructuredText
function onOpen() {
var ui = DocumentApp.getUi();
ui.createMenu('Convert to .RST')
.addItem('Convert to .RST and email me the result', 'ConvertToRestructuredText')
.addToUi();
}
// Adopted from https://github.com/mangini/gdocs2md by Renato Mangini
// License: Apache License Version 2.0
String.prototype.repeat = String.prototype.repeat || function(num) {
@gregorynicholas
gregorynicholas / gist:e9ef618818a1cfe62f7392dedee4407e
Created June 19, 2018 18:43 — forked from simonw/gist:68d19a46e8edc2cd8c68
Fix "Do you want the application "python" to accept incoming network connections?" by code signing the python executable in your virtualenv - copied here in case https://www.darklaunch.com/2014/02/02/fix-do-you-want-the-application-python-to-accept-incoming-network-connections ever goes away.
With the OS X firewall enabled, you can remove the "Do you want the application "python" to accept incoming network connections?" message.
Create a self-signed certificate.
Open Keychain Access. Applications > Utilities > Keychain Access.
Keychain Access menu > Certificate Assistant > Create a Certificate...
Enter a Name like "My Certificate".
Select Identity Type: Self Signed Root
Select Certificate Type: Code Signing
Check the Let me override defaults box
@gregorynicholas
gregorynicholas / example_output.json
Created June 19, 2018 18:42 — forked from simonw/example_output.json
Python function for retrieving all git commits (from "git log" in the current directory) as a useful data structure
[
{
"date": "Mon Jan 23 13:03:00 2017 -0800",
"message": "Recommended by Django https://docs.djangoproject.com/en/1.10/ref/databases/#setting-sql-mode",
"title": "SET sql_mode='STRICT_TRANS_TABLES';",
"hash": "a395f401c9a6d3e8602b80ecc729d736da871f46",
"author": "Simon Willison <[email protected]>"
},
{
"date": "Mon Jan 23 11:37:38 2017 -0800",
@gregorynicholas
gregorynicholas / datasettes-osx.md
Created June 19, 2018 18:42 — forked from simonw/datasettes-osx.md
Some interesting datasettes on OS X

Not sure what these are:

datasette ~/Library/Suggestions/*.db

Safari stuff:

datasette ~/Library/Safari/*.db

Your desktop background:

@gregorynicholas
gregorynicholas / configuring_cors_s3.md
Created June 19, 2018 18:41 — forked from simonw/configuring_cors_s3.md
Configuring CORS on Amazon S3 for direct image upload from JavaScript
@gregorynicholas
gregorynicholas / awesomplete-ajax.html
Created June 19, 2018 18:41 — forked from simonw/awesomplete-ajax.html
Awesomplete ajax example.
<link rel="stylesheet" href="http://leaverou.github.io/awesomplete/awesomplete.css">
<script src="http://leaverou.github.io/awesomplete/awesomplete.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
const input = document.querySelector('input.blah');
const awesomplete = new Awesomplete(input);
input.addEventListener("awesomplete-selectcomplete", (ev) => console.log(ev.text));
input.addEventListener('keyup', (e) => {
var code = (e.keyCode || e.which);
if (code === 37 || code === 38 || code === 39 || code === 40 || code === 27 || code === 13) {
@gregorynicholas
gregorynicholas / index_django_docs_to_elasticsearch.py
Created June 19, 2018 18:41 — forked from simonw/index_django_docs_to_elasticsearch.py
Example code for converting Django docs into a format suitable for import into Elasticsearch - for a talk I'm giving.
#!/usr/bin/env python
import re
import os
import urlparse
import hashlib
import json
import sys
title_re = re.compile(r'([=*]{3,})\n([^\n]+)\n\1\n')
@gregorynicholas
gregorynicholas / recover_source_code.md
Created June 19, 2018 18:35 — forked from simonw/recover_source_code.md
How to recover lost Python source code if it's still resident in-memory

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
var authExpirationHandler,
errorHandler;
function catchUnauthorizedResponses(data) {
if (data.status === 401 && !maybeLocalStorage.getItem("token")) {
// ensure the in-memory session really is expired before destroying it
return axios.get("/api/auth/session").then(
(response) => {
// we ARE still auth'd, so just throw the error down the chain
throw data;