Skip to content

Instantly share code, notes, and snippets.

View almost's full-sized avatar

Thomas Parslow almost

View GitHub Profile
View toastkenizer.py
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 = {}
View triangles.py
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;
View tree-iterator.js
class Tree {
constructor(value, left, right) {
this.left = left;
this.value = value;
this.right = right;
}
}
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 / crawler.js
Last active November 22, 2018 09:30
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 WithDimensions.js
// @flow
import React, { Component } from "react";
import { Dimensions } from "react-native";
type DimensionsState = { window: { width: number, height: number } };
type Props = {
children: (dimensions: DimensionsState) => React.Element<*>
};
View gist:ef7eceac380209961ae6681c5c95282d
UPDATE: The 1 can be either LEFT aligned (as shown) or RIGHT aligned, either will be accepted
###
# #
# #
# #
###
#
#
@almost
almost / codegolf.md
Last active August 21, 2017 01:00
Problems from last night's Code Golf at Async.JS
View codegolf.md

Yes? No?

Make a function (named 'play') that takes a boolean (true or false) and returns the string 'y' (for true) or 'n' (for false)

To the power of JavaScript

Make a function that takes a number between 1 and 30 and returns 2 raised to the power of that number. (you can use ES2015 but nothing beyond that)

@almost
almost / learning-timetable.md
Created July 2, 2016 16:43
My plan for the next 2 weeks of solid learning. I doubt I'll stick to it exactly but it gives me a framework to start with
View learning-timetable.md
@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
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).