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
@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
@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 / 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 / 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];
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 / bob.rs
Created October 23, 2017 17:51
pub fn reply(message: &str) -> &str {
let chrs = || message.trim().chars();
let has_text = chrs().any(|c| c.is_alphanumeric());
let has_letters = chrs().any(|c| c.is_alphabetic());
let has_lowercase = chrs().any(|c| c.is_alphabetic() && !c.is_uppercase());
if has_letters && has_text && !has_lowercase { "Whoa, chill out!" }
else if chrs().as_str().ends_with("?") { "Sure." }
else if !has_text { "Fine. Be that way!" }
else { "Whatever." }
pub fn nth(n: usize) -> Result<u64, &'static str> {
if n <= 0 { Err("No primes below 1") }
else {
match (2..).filter(|&x| is_prime(x)).nth(n - 1) {
Some(n) => Ok(n),
None => Err("Iteration error")
}
}
}
@lf94
lf94 / flip.lisp
Last active December 11, 2017 02:13
Essentially a coin flip smart contract, written in LLL.
{ (include './contract.lll'
(def 'enough-paid (>= callvalue required-amount))
(def 'enough-betters (>= number-of-betters required-betters))
(def 'is-paying-out (= paying-out 1))
(def 'minimum-bet-amount 10) ; Wei
(def 'required-betters 10)
(init {
@lf94
lf94 / ui.rs
Created December 16, 2017 21:50
trait Component {
fn draw(&self, ctx: &mut Context) -> ();
fn get_children(&self) -> Vec<Component>;
}
struct Label {
children: Vec<Component>,
text: graphics::Text,
color: graphics::Color,
position: graphics::Point,
@lf94
lf94 / zmap.py
Created June 17, 2018 00:16
zmap to ply converter
def toAddress(bytes):
return int.from_bytes(bytes, byteorder='big')
class Map:
# Map structure is tied to a file
def __init__(self, fileHandle):
self.fileHandle = fileHandle
self.header = self.Header(fileHandle)
fileHandle.seek(toAddress(self.header.commands[-1].data))
self.mesh = Mesh(fileHandle)