Skip to content

Instantly share code, notes, and snippets.

View lawrencejones's full-sized avatar

Lawrence Jones lawrencejones

View GitHub Profile
@lawrencejones
lawrencejones / pintos.sh
Created March 2, 2014 12:18
SCP's relevant pintos tools from one machine to another
#!/bin/bash
echo Enter MacBook Air IP:
read IP
echo Enter username for MacBook Air:
read USR
export MBA=$USR@$IP
echo Transferring...
scp -r $MBA:/usr/local/pintos-utils /usr/local/
scp -r $MBA:/usr/local/i386-elf-gcc /usr/local/
@lawrencejones
lawrencejones / DivdeAndConquer.make
Created March 2, 2014 13:33
Makefile for algorithms divide and conquer
# Makefile for Divide and Conquer
## LIST - all categories of source
## TEST - all test related source
## ANAL - all analyse related source
LDFLAGS = -lm -lstdc++
CXXFLAGS = -Wall -g
CXX=g++
VPATH= c++
#include "userprog/exception.h"
#include "userprog/gdt.h"
#include "userprog/pagedir.h"
#include <inttypes.h>
#include <stdio.h>
#include "threads/interrupt.h"
#include "threads/thread.h"
#include "threads/pte.h"
#include "vm/page.h"
In kernel.o:
0xc0020c92: thread_foreach (..../../threads/thread.c:532)
0xc0028ada: debug_backtrace_all (...../lib/kernel/debug.c:122)
0xc002bf7c: page_fault (.../userprog/exception.c:178)
0xc002207d: intr_handler (..../threads/interrupt.c:367)
0xc0022280: intr_entry (threads/intr-stubs.S:38)
In kernel.o:
0xc0020c92: thread_foreach (..../../threads/thread.c:532)
@lawrencejones
lawrencejones / get_token.sh
Last active August 29, 2015 13:58
Example of how to pull data from new cate api.
#!/bin/sh
echo "Enter college login:"
read user
echo "Enter password:"
read -s pass; echo
creds="{\"user\":\"$user\",\"pass\":\"$pass\"}"
# Pull JSON { token: <token> }
expect = (a,b) ->
[a,b] = [a.join(), b.join()]
if a != b
console.log """
Expect failed!
[#{a}] != [#{b}] """
else console.log "PASS! [#{a}]"
# Preprocesses P to generate list of occurances of suffixs within
# the pattern.
@lawrencejones
lawrencejones / merge.coffee
Created April 15, 2014 21:41
Implementation of a merge sort
PASSED = 0
check_sorted = (was, now) ->
if !now.reduce ((a,c,i) -> a && (!now[i+1]? || now[i] < now[i+1])), true
throw new Error """\n
Was: [#{was}]
Now: [#{now}]\n"""
else
++PASSED
@lawrencejones
lawrencejones / interleave.coffee
Last active August 29, 2015 14:00
Permutation generator. An example of how to divide tasks and facilitate real concurrency using Node's child_process libraries.
# Calculates time interval between start and end, formatted as
# 17928 -> 17s 928ms
timeElapsed = (start, end) ->
diff = end - start
"#{Math.floor(diff/1000)}s #{Math.floor(diff%1000)}m"
# Helpers for the permute function
arrayExcept = (A, idx) ->
(A = A[0..]).splice idx, 1; A
@lawrencejones
lawrencejones / coins.coffee
Last active August 29, 2015 14:00
Example of dynamic programming problem
# Simply rounds to four digits
dp = (num) ->
Math.round(10000*num)/10000
# Calculates empirical probability of
lazyCheck = (P, k) ->
RUNS = 500000
avg = 0
for i in [1..RUNS]
heads = P.reduce(((a,c) ->
@lawrencejones
lawrencejones / seq.coffee
Last active August 29, 2015 14:00
LCS algorithm making use of dynamic programming
# Making comparisons between two DNA sequences can become a hard computational
# problem, due to the inexact definition of organic similarity.
#
# When making comparisons between two sequences, a useful definition of
# similarity is the largest subsequence present within both sequences, where a
# subsequence is defined as such...
#
# Given X = { X1, X2, ..., Xm }
# and Z = { Z1, Z2, ..., Xk }...
#