Skip to content

Instantly share code, notes, and snippets.

@jochasinga
jochasinga / app.js
Last active May 8, 2021 20:16
Node/Socket.io server code for syncing data from Firebase
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 / json_to_instances.go
Last active January 12, 2020 15:47
How to convert JSON blob into an array of instances
package main
import (
"encoding/json"
"fmt"
)
type Person struct {
Name string
Age int
@jochasinga
jochasinga / bst.es6
Created February 6, 2017 03:15
Binary search tree implemented in ES6
'use strict';
class Node {
constructor(data) {
this.data = data;
this.left = undefined;
this.right = undefined;
}
@jochasinga
jochasinga / DemoFingerprintActivity.java
Created October 3, 2019 17:05
Example of HeadSpin's HSFingerprintManager usage
/*-
* #%L
* Demo Fingerprint Authentication Activity
* %%
* Copyright (C) 2019 Headspin Inc.
* %%
* #L%
*/
package com.nextunicorn.app;
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jochasinga
jochasinga / fork_and_wait.c
Created March 22, 2019 19:20
Fork and wait system calls
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.
const baseConfig = {
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
headers: {
"Content-Type": "application/json; charset=utf-8",
},
redirect: "follow",
referrer: "no-referrer",
};
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 March 7, 2019 01:40
Step one in refactor
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 / newton-sqrt.scm
Created November 19, 2018 12:34
Newton's method of finding a square root
(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