This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const canvas = document.getElementById("tutorial"); | |
const context = canvas.getContext("2d"); | |
function drawBackground() { | |
context.beginPath(); | |
context.fillStyle = "rgb(200, 200, 200)"; | |
context.rect(0, 0, 640, 480); | |
context.fill(); | |
context.closePath(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Length<T extends any[]> = T["length"]; | |
type Head<T extends any[]> = T[0]; | |
type Tail<T extends any[]> = ((...xs: T) => any) extends (x: any, ...t: infer T) => any ? T : never; | |
type Last<T extends any[]> = { | |
0: never; | |
1: T[0]; | |
">1": Last<Tail<T>>; | |
}[Length<T> extends 0 ? 0 : Length<T> extends 1 ? 1 : ">1"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
/* | |
* @fileoverview Program to free the content in kindle books as plain HTML. | |
* | |
* This is largely based on reverse engineering kindle cloud app | |
* (https://read.amazon.com) to read book data from webSQL. | |
* | |
* Access to kindle library is required to download this book. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function promiseMap(inputValues, mapper) { | |
const reducer = (acc$, inputValue) => | |
acc$.then(acc => mapper(inputValue).then(result => acc.push(result) && acc)); | |
return inputValues.reduce(reducer, Promise.resolve([])); | |
} | |
/* Example */ | |
const axios = require('axios'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Importer | |
CODES = {:header, "00F", :data => "00I"} | |
def self.import_products(fileobj) | |
fileobj.lines.each_slice(4).map do |group_lines| | |
type, *data_lines = group_lines.map(&:strip) | |
case type | |
when CODES[:header] | |
# what to do/return here? | |
when CODES[:data] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# $loopc 3 echo 'hello world' | |
# hello world | |
# hello world | |
# hello world | |
# | |
function loopc { | |
LIMIT=$1 | |
shift 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'eventmachine' | |
$stdout.sync = true | |
$stderr.sync = true | |
EM.run { | |
EM.add_periodic_timer(0.1) { | |
$stdout.write "stdout\n" |