This file contains hidden or 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
| // This is tricky because you cannot do Str extends `${infer Before}${UnionOfSep}${infer After}` ... | |
| type Split<Str, UnionOfSep extends string, CurrentWord extends string = "", Output extends string[] = []> = | |
| Str extends `${infer First}${infer Rest}` | |
| ? First extends UnionOfSep | |
| ? Split<Rest, UnionOfSep, "", [...Output, CurrentWord]> | |
| : Split<Rest, UnionOfSep, `${CurrentWord}${First}`, Output> | |
| : [...Output, CurrentWord]; |
This file contains hidden or 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
| /** | |
| * The `navigate` function takes a `Path` string that | |
| * can contain parameter names using the `users/:username` | |
| * syntax. Type it so that the `params` object provided | |
| * as the second argument always contains a key for each variable | |
| * in the `Path`. | |
| */ | |
| namespace parseUrlParams { | |
| declare function navigate<U extends string>( | |
| path: U, |
This file contains hidden or 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
| let map = (func, [head, ...tail]) => head === undefined ? [] : [func(head), ...map(func, tail)] | |
| map(n => n + 1, [1, 2, 3]) | |
| // [2, 3, 4] |
This file contains hidden or 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
| def square_root(x, guess) | |
| puts "guessing: #{guess}" | |
| if guess * guess == x | |
| guess | |
| else | |
| new_guess = (guess + x / guess) / 2 | |
| square_root(x, new_guess) | |
| end | |
| end |
This file contains hidden or 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
| % The beauty of the right programming paradigm. | |
| % Conway's Game of life in 4 lines of Octave code. | |
| function new = life(board) | |
| neighbours = conv2(board, [1 1 1; 1 0 1; 1 1 1], 'same') | |
| new = neighbours == 3 | (neighbours == 2 & board) | |
| end | |
| % Create a 100x100 board and run the game in a GUI |
This file contains hidden or 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
| var expect = require("chai").expect | |
| var gameOrig = "../game" | |
| var gameGood = "../game.good" | |
| var capturingConsole = function(action) { | |
| var log = console.log | |
| var logs = [] | |
| global.console.log = function(msg) { | |
| logs.push(msg) |
This file contains hidden or 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 bash | |
| if [ "$1" == "" ]; then | |
| echo "Usage: deploy <command>" | |
| echo "Execute <command> in the mirror of the dir you are in under /var/www" | |
| echo "e.g. deploy php scripts/BusinessKnowledgeImport.php --force --only-external-rules" | |
| exit 1 | |
| fi | |
| deploy_dir="/var/www" |
This file contains hidden or 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
| describe "wait after pressButton", -> | |
| before (done)-> | |
| brains.get "/two-timers-only-the-first-useful", (req,res)-> | |
| res.send """ | |
| <html> | |
| <body> | |
| <button id="pressMe">press me</button> | |
| <script> | |
| var button = document.getElementById("pressMe") | |
| button.addEventListener("click", function(ev) { |
This file contains hidden or 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
| Browser.prototype.isGradeA = function() { | |
| var browser = this | |
| browser.on("response", function(res, target) { | |
| var window = browser.window | |
| var document = browser.document | |
| var onMobileInitMakeGradeA = function() { | |
| if (window.$) { | |
| window.$(document).on("mobileinit", function() { | |
| window.$.mobile.gradeA = function() { return true } | |
| }) |
This file contains hidden or 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
| // ==================================== | |
| // Example: Nesting callbacks to produce serial requests | |
| server.on('request', function(req, res) { | |
| //get session information from memcached | |
| memcached.getSession(req, function(session) { | |
| //get information from db | |
| db.get(session.user, function(userData) { | |
| //some other web service call | |
| ws.get(req, function(wsData) { |
NewerOlder