Skip to content

Instantly share code, notes, and snippets.

View almost's full-sized avatar

Thomas Parslow almost

View GitHub Profile
@almost
almost / countries.json
Last active April 29, 2024 13:41 — 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)
[
{"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"},
import re,sys
from typing import Iterable, List
CHARACTERS = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ:!,.'() ")
END = "___END___"
class Toastkenizer:
def __init__(self, characters:List[str]=CHARACTERS, tokens:List[str] = []):
self.characters = characters
self.tokens_trie = {}
@almost
almost / django-template.py
Last active January 3, 2023 08:35
Compile Django Templates from the command line
#!/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 November 17, 2022 14:05
Test React Native on the simulator and on a device without editing the code each time!

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:
round = 500.0;
def setup():
size(1000, 1000)
def xy(i):
global round
dist = float(i * 2);
angle = (i/((float(round)+500)))*360
x = cos(angle)*dist;
@almost
almost / proposal.md
Last active September 12, 2019 09:07
Reactive 2016 Lightning Talk Proposal: Get Flow

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 September 12, 2019 09:07
Reactive 2015 Lightning Talk Proposal: Pyramids be gone!: ES7 Async Function

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 / gifextract.py
Last active June 17, 2019 14:26 — forked from BigglesZX/gifextract.py
Extract frames from an animated GIF and return them from a generator, correctly handling palettes and frame update modes
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).
class Tree {
constructor(value, left, right) {
this.left = left;
this.value = value;
this.right = right;
}
}
@almost
almost / crawler.js
Last active November 22, 2018 09:30
// 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;