Skip to content

Instantly share code, notes, and snippets.

View jmoyers's full-sized avatar

Joshua Moyers jmoyers

View GitHub Profile
@jmoyers
jmoyers / cool.y
Created June 11, 2016 07:01
bison parser for cool
%{
#include <iostream>
#include "cool-tree.h"
#include "stringtab.h"
#include "utilities.h"
extern char *curr_filename;
/* Locations */
#define YYLTYPE int /* the type of locations */
#define cool_yylloc curr_lineno /* use the curr_lineno from the lexer
for the location of tokens */
@jmoyers
jmoyers / myparser.sh
Created June 7, 2016 22:23
An updated version of Stanford Compilers myparser script
#!/bin/bash
# -d = loads your parser into gdb with correct input
# -r = uses the ref lexer and parser to generate the same style output
# default, the way the script worked originally
if [ $1 = "-d" ]; then
shift
./lexer $* > lexer.out
gdb -ex "set args $* < lexer.out" ./parser
elif [ $1 = "-r" ]; then
shift
#!/bin/sh
# http://jmoyers.org/minimal-tmux-dev/
# Create a 3 paned tmux window with vim on left
# v [file]
tmux new-session -d -s dev
tmux new-window -t dev
tmux rename-window 'Dev'
tmux split-window -h
tmux split-window -v
tmux select-pane -t 0
# remap C-b to C-a
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# reload the conf file on the fly
bind r source-file ~/.tmux.conf
# who knows what this does, but I can now scroll in a tmux pane
set -g terminal-overrides 'xterm*:smcup@:rmcup@'
// From https://thesquareplanet.com/blog/the-path-to-rust/
// Example 2: non-functional
let mut idx = HashMap::new();
for fname in &args {
let f = match fs::File::open(fname) {
Ok(f) => io::BufReader::new(f),
Err(e) => panic!("input file {} could not be opened: {}", fname, e),
};
let mut words = HashSet::new();
for line in f.lines() {
// From https://thesquareplanet.com/blog/the-path-to-rust/
// Example 1: functional
let idx = args
// iterate over our arguments
.iter()
// open each file
.map(|fname| (fname.as_str(), fs::File::open(fname.as_str())))
// check for errors
.map(|(fname, f)| { f.and_then(|f| Ok((fname, f)))
.expect(&format!("input file {} could not be opened", fname))
@jmoyers
jmoyers / memcpy.asm
Last active May 26, 2016 22:44
memcpy
// 00F61000 push ebp ; save base pointer
// 00F61001 mov ebp, esp ; create new stack frame
// 00F61003 sub esp, 10h ; give me 16 bytes (2 x 8 byte struct)
// 00F61006 mov dword ptr[ebp - 8], 0FFh ; store 0xff into first 8 bytes on stack (a.v1)
// 00F6100D push 8 ; param 3: push 8 onto the stack (sizeof struct)
// 00F6100F lea eax, [ebp - 8] ; eax = address of start of a
// 00F61012 push eax ; param 2: push the address of "a" onto stack
// 00F61013 lea ecx, [ebp - 10h] ; ecx = address of start of b
// 00F61016 push ecx ; param 1: push address of "b" onto the stack
// 00F61017 call 00F62716 ; call memcpy -- we'll grab asm and put below
@jmoyers
jmoyers / ProximityLight.cpp
Created March 22, 2014 09:54
Blueprint integration
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
#include "TestUnrealCodeProject.h"
#include "ProximityLight.h"
AProximityLight::AProximityLight(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
PointLight = PCIP.CreateDefaultSubobject<UPointLightComponent>(this, "PointLight");
// Module dependencies
var express = require( 'express' )
var app = module.exports = express.createServer()
var io = require( 'socket.io' ).listen(app)
var fs = require( 'fs' )
var net = require( 'net' )
var cdr = require( './cdr' )
var filename = './test/test.csv';
@jmoyers
jmoyers / luvit
Created September 25, 2011 22:04
luvit ab
This is ApacheBench, Version 2.3 <$Revision: 1139530 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests