Skip to content

Instantly share code, notes, and snippets.

View lf94's full-sized avatar
🏔️
Hey how's it going

49fl lf94

🏔️
Hey how's it going
View GitHub Profile
pub fn verse(n: i32) -> String {
if n > 2 {
format!("{0} bottles of beer on the wall, {0} bottles of beer.\nTake one down and pass it around, {1} bottles of beer on the wall.\n", n, n - 1)
} else if n == 2 {
format!("2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n")
} else if n == 1 {
format!("1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n")
} else {
format!("No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n")
}
@lf94
lf94 / viterbi.js
Created January 22, 2017 18:28 — forked from methodin/viterbi.js
Viterbi
// Viterbi algorithm for finding hidden relationships
function Viterbi(data) {
var V = [{}];
var path = {};
// Initialize base cases (t == 0)
for(var i=0;i<data.states.length;i++) {
var state = data.states[i];
V[0][state] = data.start_probability[state] * data.emission_probability[state][data.observations[0]];
path[state] = [state];
@lf94
lf94 / Opus\asm\inssubsn.asm
Created November 8, 2016 00:14
One of the main text insertion routines in Word 1.1a. In assembly yet.
;-------------------------------------------------------------------------
; FcAppendRgchToFn(fn, pch, cch)
;-------------------------------------------------------------------------
;/* F C A P P E N D R G C H T O F N */
;/* Appends characters pointed to by pch, length cch, to end of file fn.
;Returns first fc written.
;If there is a free hole of sufficient size in vfkpdText, it will be
;used instead.
;fcLim updated to point to after the last char written.
;*/
@lf94
lf94 / Opus\wordtech\insert.c
Created November 8, 2016 00:07
The main character insert routine comments from Opus\wordtech\insert.c
The programmer bryanl left some real nice comments in the source code. I bet he never expected it to be looked at years later. I've added some commentary myself too.
Line 412:
When a character is typed, it is inserted at rgchInsert[ichInsert++].
When rgchInsert is full, it is written to the scratch file, and Replace'd
with a new insertion block.
Line 222:
fc = FcAppendRgchToFn(fnScratch, rgchInsert, ichInsert);
@lf94
lf94 / atom.js
Created November 6, 2016 15:38
A view of Atom's text insertion routine
# Applies a change to the buffer based on its old range and new text.
applyChange: (change) ->
{newStart, oldExtent, newExtent, oldText, newText, normalizeLineEndings} = change
start = Point.fromObject(newStart)
oldRange = Range(start, start.traverse(oldExtent))
newRange = Range(start, start.traverse(newExtent))
oldRange.freeze()
newRange.freeze()
@cachedText = null
;; Calculate the location of Sprite 1
ld hl, wOAMAddr
ld de, wOAM
ld [hl], d
inc hl
ld [hl], e
mUpdateSprite 80, 40, $59, 0, 2, 3
@lf94
lf94 / partial.asm
Created October 5, 2016 16:05
Beautiful macro
loop:
call WaitVBlank
mUpdateSprite 0, 100, 80, $59, 0, 2, 3
call _HRAM
jp loop
@lf94
lf94 / boot.asm
Created October 2, 2016 22:21
Check to see if OAM DMA doesn't write unused bits
INCLUDE "Global.inc"
; Cartridge header
SECTION "Org $00",ROM0[$00]
RST_00:
jp $100
SECTION "Org $08",ROM0[$08]
RST_08:
@lf94
lf94 / boot.asm
Created September 29, 2016 13:34
Trying to come up with a de-facto way of booting.
INCLUDE "Global.inc"
; Cartridge header
SECTION "Org $00",HOME[$00]
RST_00:
jp $100
SECTION "Org $08",HOME[$08]
RST_08:
@lf94
lf94 / vtwm.txt
Created September 16, 2016 17:15
vtwm
Hey, this is a long shot, but here goes.
I have this defined in my .vtwmrc configuration file:
Function "map-show" { f.showdesktopdisplay f.warpto "VTWM Desktop" }
Function "iconmgr-show" { f.showiconmgr f.warpto "VTWM Icon Manager" }
called with:
"Space" = control : all : f.function "map-show"
"Space" = shift : all : f.function "iconmgr-show"