Skip to content

Instantly share code, notes, and snippets.

@FLamparski
FLamparski / ugly.md
Last active October 25, 2015 17:02
A bookmarklet to un-uglify default styles for text-heavy but style-light web pages

Loads of HTML out there is unstyled, so you get a whole lot of 1990 in your browser. If you prefer it to be prettier, try this:

(function(){
  var s = document.body.style;
  s.maxWidth='660px';
  s.margin='8px auto';
  s.fontFamily='Source Sans Pro'; // adjust to your liking
 s.fontSize='16px';
@FLamparski
FLamparski / index.js
Created November 26, 2015 10:34
requirebin sketch
var yaml = require('yamljs')
var _ = require('lodash')
function print(s) {
var p = document.createElement('p')
p.appendChild(document.createTextNode(s))
document.body.appendChild(p)
}
var o = {a: 1, b: [{a: 2}, {c: 3}], x: 'lol what'}
@FLamparski
FLamparski / compose.php
Created December 15, 2015 13:40
A semi-workable implementation of functional composition in PHP.
<?php
/*
This function takes in a bunch of callables (closures, functions, strings naming functions, etc.)
and returns a function such that compose(f, g)(x) <=> f(g(x)). In other words, the return function
will take exactly one argument, and call the functions supplied to compose right to left
on that argument.
*/
function compose() {
$functions = func_get_args();
return (function() use ($functions) {
>>> function coerc2($optional = null) { printf("Optional is set? %b, Is coercable to true? %b\n", isset($optional), (bool) $optional); }
=> null
>>> coerc2()
Optional is set? 0, Is coercable to true? 0
=> null
>>> coerc2(1)
Optional is set? 1, Is coercable to true? 1
=> null
>>> coerc2(2)
Optional is set? 1, Is coercable to true? 1
@FLamparski
FLamparski / FakeLoops.kt
Last active January 2, 2016 21:10
Let's reimplement while and for loops in Kotlin with its omit-parens-around-last-function-argument syntax
fun wwhile (cond: () -> Boolean, body: () -> Unit) {
if (cond()) {
body()
wwhile(cond, body)
}
}
fun <T> ffor(initialise: () -> T, check: (T) -> Boolean, step: (T) -> T, body: (T) -> Unit) {
var loopvar = initialise()
wwhile({check(loopvar)}) {
@FLamparski
FLamparski / README.md
Created March 27, 2016 18:41
Messing about with context-free generative grammars in Python

I'm messing about with generative context-free grammars in Python. The generator itself is in gen_grammar.py, and the test grammar used is in grammar.json.

Program usage

$ ./gen_grammar.py grammar.json will generate a single sentence from the given grammar.

Grammar format

@FLamparski
FLamparski / queue.js
Created June 13, 2016 11:28
A rate-limiting queue for promised jobs
const _ = require('lodash')
/**
* A rate-limiting queue for functions that return promises.
*
* const q = new Queue({rate: 1000})
* Promise.all(_.range(10).map(n => q.push(() => n * n))).then(all => console.log(all))
* q.start()
* // ten seconds later => [ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81 ]
*
@FLamparski
FLamparski / index.html
Created June 22, 2016 09:08
Comparing methods to create a Moment object (https://jsbench.github.io/#bae40c8c11c78668b0f2ae9a6caae025) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Comparing methods to create a Moment object</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@FLamparski
FLamparski / index.html
Created June 22, 2016 13:40
Checking for existence of a property (https://jsbench.github.io/#eeccc7f9e560816ad321234e1deab0ea) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Checking for existence of a property</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@FLamparski
FLamparski / README.markdown
Created July 4, 2016 20:08
Learning Elixir: A shitty program that does things with data

Crapitals

Filip Learns Elixir, Day 1

Basically, it's a thing which reads data from a CSV file, keeps it in memory using a stateful process CountryList, and lets you query said list. I tried using several of Elixir's features here such as processes, messaging, pattern-matching, and the pipe operator.