Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Joe Chasinga jochasinga

🏠
Working from home
Block or report user

Report or block jochasinga

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jochasinga
jochasinga / bst.es6
Created Feb 6, 2017
Binary search tree implemented in ES6
View bst.es6
'use strict';
class Node {
constructor(data) {
this.data = data;
this.left = undefined;
this.right = undefined;
}
@jochasinga
jochasinga / app.js
Last active Jul 30, 2019
Node/Socket.io server code for syncing data from Firebase
View app.js
var Firebase = require("firebase");
var express = require("express");
// Create HTTP Server
var app = express();
var server = require("http").createServer(app);
// Attach Socket.io server
var io = require("socket.io")(server);
// Indicate port 3000 as host
var port = process.env.PORT || 3000;
@jochasinga
jochasinga / fork_and_wait.c
Created Mar 22, 2019
Fork and wait system calls
View fork_and_wait.c
include <stdio.h>
include <stdlib.h>
include <unistd.h>
include <sys/wait.h>
int main(int argc, char *argv[])
{
printf("hello world (pid:%d)\n", (int) getpid());
int rc = fork();
// Fork failed, let's exit.
View refactor3.js
const baseConfig = {
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
headers: {
"Content-Type": "application/json; charset=utf-8",
},
redirect: "follow",
referrer: "no-referrer",
};
View refactor2.js
const baseConfig = {
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
headers: {
"Content-Type": "application/json; charset=utf-8",
},
redirect: "follow",
referrer: "no-referrer",
};
@jochasinga
jochasinga / refactor1.js
Last active Mar 7, 2019
Step one in refactor
View refactor1.js
async function postLoginData(data) {
const loginUrl = `${apiBaseUrl}/login`;
let response = await fetch(loginUrl, {
method: "POST",
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
headers: {
"Content-Type": "application/json; charset=utf-8",
},
@jochasinga
jochasinga / json_to_instances.go
Last active Jan 9, 2019
How to convert JSON blob into an array of instances
View json_to_instances.go
package main
import (
"encoding/json"
"fmt"
)
type Person struct {
Name string
Age int
@jochasinga
jochasinga / newton-sqrt.scm
Created Nov 19, 2018
Newton's method of finding a square root
View newton-sqrt.scm
(define (square-of x)
(define (average x y)
(/ (+ x y) 2))
(define (improve guess x)
(average guess (/ x guess)))
(define (good-enough? guess x)
(< (abs (- (square-of guess) x)) 0.001))
(define (sqrt-iter guess x)
(if (good-enough? guess x)
guess
@jochasinga
jochasinga / newton.csv
Created Nov 19, 2018
Table demonstrating Newton's square root method derivation
View newton.csv
Guess Quotient Average
1 2/1 = 2 (2 + 1)/2 = 1.5
1.5 2/1.5 = 1.3333 1.3333 + 1.5/2 = 1.4167
1.4167 2/1.4167 = 1.4118 (1.4167 + 1.4118)/2 = 1.4142
1.4142 ... ...
View two_mod.ml
module State = struct
type t = int
let inc (n: t) = Transformer.inc n
end
;;
module Transformer = struct
let inc (n: State.t) = n + 1
end
;;
You can’t perform that action at this time.