Skip to content

Instantly share code, notes, and snippets.

View sean3z's full-sized avatar

Sean Wragg sean3z

View GitHub Profile
@sean3z
sean3z / server.js
Created May 29, 2018 23:54
Restify JWT example
const user = require('./lib/user');
app.post('/auth', (req, res, next) => {
let {username, password} = req.body;
user.authenticate(username, password).then(data => {
res.send(data);
})
});
@sean3z
sean3z / user.js
Last active May 30, 2018 01:14
Restify JWT example
"use strict";
exports.authenticate = (username, password) => {
return Promise.resolve({ uid: 1, name: 'Sean', admin: false });
};
/*
exports.authenticate = (username, password) => {
return new Promise((resolve, reject) => {
db.findOne({username, password}, (err, data) => {
@sean3z
sean3z / config.json
Created May 29, 2018 23:45
Restify JWT example
{
"jwt": {
"secret": "&@$!changeme!$@&"
}
}
@sean3z
sean3z / server.js
Last active May 30, 2018 01:04
Restify JWT example skeleton
"use strict";
const restify = require('restify');
const config = require('./config');
const app = restify.createServer();
app.use(restify.plugins.queryParser());
app.use(restify.plugins.bodyParser());
app.listen(8080, () => {
@sean3z
sean3z / cpu.rs
Last active December 30, 2022 00:36
Example CPU module
use rand;
use std::fs::File;
use display::Display;
use keypad::Keypad;
pub struct Cpu {
program: usize, // program counter starts at 512 bytes
opcode: u16, // current opcode
stack: [u16; 16], // stack storage
@sean3z
sean3z / main.rs
Last active December 30, 2022 00:27
Example main
use cpu::Cpu;
mod cpu;
mod keypad;
mod display;
fn main() {
let mut cpu = Cpu::new();
cpu.load_game("/home/sean/www/chip8-emulator-rust/roms/pong");
@sean3z
sean3z / system.rs
Last active May 15, 2018 03:25
Example System
use cpu::Cpu;
use display::Display;
use keypad::Keypad;
pub struct System {
cpu: Cpu,
memory: [u8; 4096],
keypad: Keypad,
display: Display
}
@sean3z
sean3z / cpu.rs
Last active December 30, 2022 00:48
Example loading ROM data into memory
pub fn load_game(&mut self, game: &str) {
// attempt to load supplied ROM
let mut reader = File::open(game).expect("Unable to locate ROM");
let mut buffer = Vec::new();
reader.read_to_end(&mut buffer).expect("Unable to read ROM data");
// load ROM into memory (AFTER system reserved memory)
for i in 0..buffer.len() {
self.memory[i + self.program] = buffer[i];
};
@sean3z
sean3z / cpu.rs
Last active December 30, 2022 01:01
Example throwing Fonts into our cpu.memory
impl Cpu {
pub fn new() -> Cpu {
let mut memory = [0; 4096];
// load fonts into memory
for i in 0..80 {
memory[i] = FONTS[i];
};
Cpu {
@sean3z
sean3z / config.php
Created April 21, 2018 15:29
drupal 6 migration example
$databases['drupal6']['default'] = array(
'driver' => 'mysql',
'database' => 'database',
'username' => 'username',
'password' => 'password',
'host' => 'hostname',
'prefix' => '',
);