Skip to content

Instantly share code, notes, and snippets.

@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' => '',
);
@sean3z
sean3z / import.php
Created April 21, 2018 15:28
Drupal 6 migration example
<?php
function import_nodes() {
db_query('DELETE FROM {node} WHERE `nid` > 1');
db_query('ALTER TABLE {node} AUTO_INCREMENT = 2');
db_query('DELETE FROM {node_revision} WHERE `nid` > 1');
db_query('ALTER TABLE {node_revision} AUTO_INCREMENT = 2');
db_query('DELETE FROM {field_revision_body} WHERE `entity_id` > 1');
db_query('DELETE FROM {field_data_body} WHERE `entity_id` > 1');
db_query('DELETE FROM {node_comment_statistics} WHERE `nid` > 1');
db_query('TRUNCATE TABLE {url_alias}');
@sean3z
sean3z / pagination.php
Last active May 10, 2022 19:09
Pagination example
<?php
function handle_pagination($total, $page, $shown, $url) {
$pages = ceil( $total / $shown );
$range_start = ( ($page >= 5) ? ($page - 3) : 1 );
$range_end = ( (($page + 5) > $pages ) ? $pages : ($page + 5) );
if ( $page >= 1 ) {
$r[] = '<span><a href="'. $url .'">&laquo; first</a></span>';
$r[] = '<span><a href="'. $url . ( $page - 1 ) .'">&lsaquo; previous</a></span>';
$r[] = ( ($range_start > 1) ? ' ... ' : '' );