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
// Discriminated Union in TypeScript | |
interface Integer { | |
tag: 'integer'; | |
value: number; | |
} | |
interface Sum { | |
tag: 'sum'; | |
op1: Expression; |
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
use std::iter::Peekable; | |
use std::str::Chars; | |
fn main() { | |
let s = "Aussonderungsaxiom".to_string(); | |
let mut bf = Buffer::new(&s); | |
println!("First character should be A: {}", bf.peek().expect("q")); | |
println!("First char: {}", bf.next().expect("q")); | |
println!("Next char: {}", bf.next().expect("q")); |
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
#lang racket | |
;; Write a simple C64 assembly program to a PRG file, along with a line | |
;; of BASIC program to load the machine-language code. | |
;; The assembly program that will be run | |
(define program | |
(bytes #xA9 #x00 ; LDA #00 | |
#x8D #x20 #xD0 ; STA $D020 | |
#x8D #x21 #xD0 ; STA $D021 |
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
// Fetch an activity from the Bored API | |
type promise<+'a> = Js.Promise.t<'a> | |
@send external then: (promise<'a>, @uncurry ('a => promise<'b>)) => promise<'b> = "then" | |
@send external thenResolve: (promise<'a>, @uncurry ('a => 'b)) => promise<'b> = "then" | |
module Response = { | |
type t<'data> | |
@send external json: t<'data> => promise<'data> = "json" |
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
// example ported from | |
// "Web Development with Node and Express", 2nd edition | |
// by Ethan Brown | |
// bindings to the node API | |
type res | |
type req | |
type server | |
@module("http") external createServer : ( @uncurry (req, res) => unit ) => server = "createServer" |
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
// removes acute accents represented in separate characters | |
// e.g. a + ' = á | |
function removeAcute(s) { | |
let res = "" | |
let i = 0 | |
for (i = 0; i < s.length; ++i) { | |
if (s.codePointAt(i) != 769) | |
res = res + s.charAt(i) | |
} | |
return res |
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
let py = document.querySelector('#playerFrame'). | |
contentDocument.querySelectorAll('rt') | |
let escondePinYin = () => py.forEach( e => e.style.color = '#FFFFFF' ) | |
let mostraPinYin = () => py.forEach( e => e.style.color = '#000000' ) |
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
#!/bin/sh | |
# Download binutils, gcc, the linux kernel, glibc | |
# define the prefix | |
export PREFIX=/opt/armhf | |
# change PATH to include the target directory | |
export PATH=$PREFIX/bin:$PATH |
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
;; sqrt function using continuations | |
;; | |
;; a port from an example in the first Scheme memo (AIM-349) | |
;; to modern Scheme | |
(define sqrt | |
(lambda (x epsilon) | |
((lambda (ans looptag) | |
(call-with-current-continuation | |
(lambda (returntag) |
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
;; product with break and O(1) case for a zero operand | |
;; call/cc | |
(define (product-cc ls) | |
(call-with-current-continuation | |
(lambda (break) | |
(cond ((null? ls) 1) | |
((= (car ls) 0) (break 0)) | |
(else (* (car ls) (product-cc (cdr ls)))))))) |
NewerOlder