Skip to content

Instantly share code, notes, and snippets.

Thomas Parslow almost

Block or report user

Report or block almost

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@almost
almost / proposal.md
Last active Sep 12, 2019
Reactive 2016 Lightning Talk Proposal: Get Flow
View proposal.md

This is a proposal for a lightning talk at the Reactive 2016 conference.

NOTE: If you like this, star ⭐️ the Gist - the amount of stars decides whether it makes the cut! You could also Retweet if you want :)

Get Flow

Type checking JavaScript with Flow

JavaScript is a dynamic language, and there's nothing wrong with that. It allows quick iteration and lowers barriers. However, sometimes some compile-time type checking is just what you need to keep your code in line and give yourself the confidence to build bigger and faster. Flow gives the best of both worlds. You can have normal JavaScript but you can also add types where they're helpful, and it adds zero cost at runtime. In this talk I'll show Flow as it applies to a Redux & React codebase.

@almost
almost / async-await-lightning-talk.md
Last active Sep 12, 2019
Reactive 2015 Lightning Talk Proposal: Pyramids be gone!: ES7 Async Function
View async-await-lightning-talk.md

This is a proposal for a lightning talk at the Reactive 2015 conference.

NOTE: If you like this, star ⭐️ the Gist - the amount of stars decides whether it makes the cut! You could also Retweet if you want :)

Pyramids be gone!

ES7 Async Functions

JavaScript is getting async functions (or already has them if you count Babel.JS) and with them a way to finally slay the evil pyramid. This new language feature lets you write asynchronous code that almost looks synchronous, while maintaining the same semantics as promises. This lets you shed your .then and .catch boilerplate and escape those nested callbacks in favour of clean, explicit, maintainable code.

@almost
almost / django-template.py
Last active Aug 27, 2019
Compile Django Templates from the command line
View django-template.py
#!/usr/bin/env python
"""
Compile Django Templates from the command line
Thomas Parslow 2014
tom@almostobsolete.net
tomparslow.co.uk almostobsolete.net
Run passing in the the template file to read and the context data as
JSON. Will output the compiled HTML on stdout.
@almost
almost / 1-react-native-simulator-and-device.md
Last active Aug 17, 2019
Test React Native on the simulator and on a device without editing the code each time!
View 1-react-native-simulator-and-device.md

In the default React Native app scaffolding you have to edit AppDelegate.m to change where it loads the code if you want to test on your device. I use the following snippet to detect if it's being compiled for Debug or Production and for the Simulator or a device. For Production it uses a copy of the code included in the bundle, for Debug on the simualtor it loads from a server on localhost and for Debug on a device it loads from a server on a given IP address.

NOTE: You need to edit YOUR-IP-HERE and change it to the IP to load the code from when in Debug mode on a device. You could use a service like ngrok to make this work from anywhere.

  NSURL *jsCodeLocation;

  // Loading JavaScript code
  #if DEBUG
    // For Debug build load from development server. Start the server from the repository root:
@almost
almost / gifextract.py
Last active Jun 17, 2019 — forked from BigglesZX/gifextract.py
Extract frames from an animated GIF and return them from a generator, correctly handling palettes and frame update modes
View gifextract.py
import os
from PIL import Image
# Based on https://gist.github.com/BigglesZX/4016539 (but adapted to be a
# generator that yields frames instead of a function that saves out frames)
'''
I searched high and low for solutions to the "extract animated GIF frames in Python"
problem, and after much trial and error came up with the following solution based
on several partial examples around the web (mostly Stack Overflow).
View tree-iterator.js
class Tree {
constructor(value, left, right) {
this.left = left;
this.value = value;
this.right = right;
}
}
View crawler.js
// Solution https://gist.github.com/almost/9ee99b1a3e7fa240c596be3820c0b6b0
"use strict";
const url = require('url');
const rp = require("request-promise-native");
const getHrefs = require("get-hrefs");
const MAX_CONCURRENT = 3;
const MAX_COUNT = 5;
View crawler-solution.js
"use strict";
const url = require("url");
const rp = require("request-promise-native");
const getHrefs = require("get-hrefs");
const MAX_CONCURRENT = 10;
const MAX_COUNT = 2000;
const ALLOW_DOMAINS = new Set(["almostobsolete.net", "tomparslow.co.uk"]);
const START_URLS = ["http://almostobsolete.net/"];
@almost
almost / countries.json
Last active Oct 22, 2018 — forked from keeguon/countries.json
A list of countries along 2 letter ISO codes in JSON format (the gist I forked from was valid JS but not valid JSON)
View countries.json
[
{"name": "Afghanistan", "code": "AF"},
{"name": "Åland Islands", "code": "AX"},
{"name": "Albania", "code": "AL"},
{"name": "Algeria", "code": "DZ"},
{"name": "American Samoa", "code": "AS"},
{"name": "AndorrA", "code": "AD"},
{"name": "Angola", "code": "AO"},
{"name": "Anguilla", "code": "AI"},
{"name": "Antarctica", "code": "AQ"},
@almost
almost / glacier.py
Created Aug 21, 2012
Amazon Glacier from Python. There's now a branch for this, see here: https://github.com/almost/boto/tree/glacier
View glacier.py
# Thomas Parslow http://almostobsolete.net
# Just a work in progress and adapted to what I need right now.
# It does uploads (via a file-like object that you write to) and
# I've started on downloads. Needs the development version of Boto from Github.
#
# Example:
#
# glacierconn = GlacierConnection(AWS_ACCESS_KEY, AWS_SECRET_ACCESS_KEY)
# writer = GlacierWriter(glacierconn, GLACIER_VAULT)
# writer.write(somedata)
You can’t perform that action at this time.