Skip to content

Instantly share code, notes, and snippets.

View linus's full-sized avatar

Linus G Thiel linus

View GitHub Profile
@linus
linus / bingo.js
Last active November 30, 2021 10:13
UK Bingo 90 board creator
// Takes a board generated by the bingo() function below, and returns
// a HTML table.
function boardToHTML(board) {
return `
<table>
${chunk(board, 3).map(card => `<tbody>
${card.map(row => `<tr>
${row.map(cell => `<td>
${cell ? cell.toString().padStart(2, '0') : ''}
</td>`).join('')}
class Video extends Inline {
get attrs() {
return {
url: new Attribute,
id: new Attribute({compute: function (attrs) {console.log(attrs);return videoRE.exec(attrs.url)[2]}}),
type: new Attribute({compute: function (attrs) {console.log(attrs);return videoRE.exec(attrs.url)[1]}}),
width: new Attribute({default: "640"}),
height: new Attribute({default: "480"})
}
}

Keybase proof

I hereby claim:

  • I am linus on github.
  • I am yesbabyyes (https://keybase.io/yesbabyyes) on keybase.
  • I have a public key whose fingerprint is DC4B 6A42 0A58 45E0 8F42 6943 30E7 9CC0 DEF0 C03E

To claim this, I am signing this object:

@linus
linus / gist:1826712
Created February 14, 2012 13:19
Variable instantiation
var foo = 1, bar = 2;
var foo = 1
, bar = 2;
var foo = 1,
bar = 2;
var foo = 1;
var bar = 2;
@linus
linus / Publish a message
Created January 4, 2012 15:54
Server-side Events with Node.js and Redis
linus@Newton:~$ redis-cli
redis 127.0.0.1:6379> publish /updates.foo "hello there!"
(integer) 1
redis 127.0.0.1:6379>
@linus
linus / ab.txt
Created December 14, 2011 02:51
Google Turkey Doodle in CoffeeScript
linus@Newton:~/development/projects/turkey$ ab -n 10000 http://localhost:3000/A012B490
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
@linus
linus / app.js
Created October 14, 2011 10:16
Matching POSTed data for artemma
var http = require("http");
// Responses for various urls
var responses = {
"/createUser": "foo",
"/deleteUser": "bar"
};
var server = http.createServer(function(req, res) {
// Listen for data on request
@linus
linus / create_better_mosaic.py
Created March 8, 2011 02:37
Så förbättrade vi Rättviseförmedlingens pressbild
# Main function. Takes the original image and a list of
# profile pictures, and returns the finished, improved, mosaic
def create_better_mosaic(original_image, profile_pictures):
# Calculate the width and height of the scaled image, where
# each profile picture maps to a pixel in the original image
width, height = image_ratio(original_image, len(profile_pictures))
# Get the pixel values of the scaled image, "unfolded" in
# one dimension
pixels = get_pixels_one_dimensional(original_image, width, height)
# Get a list of tuples with (image, color) for each profile picture
@linus
linus / color_distance.py
Created March 2, 2011 12:27
Så gjorde vi Rättviseförmedlingens pressbild
# Return the Euclidean distance between color_a and color_b.
# We optimize a little and don't calculate the square root of the distance.
# The sum of the squares of deltas is good enough.
def color_distance(color_a, color_b):
delta_red = color_a[0] - color_b[0]
delta_green = color_a[1] - color_b[1]
delta_blue = color_a[2] - color_b[2]
return delta_red * delta_red + delta_green * delta_green + delta_blue * delta_blue
@linus
linus / complex.coffee
Created December 27, 2010 19:27
Mandelbrot set in CoffeeScript and Canvas
# Complex class from http://docstore.mik.ua/orelly/webprog/jscript/ch08_05.htm#jscript4-CHP-8-EX-6
class Complex
constructor: (@x, @y) ->
magnitude: ->
Math.sqrt @x * @x + @y * @y
negative: ->
new Complex -@x, -@y