This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[post("/", data = "<hero>")] | |
| fn create(hero: Json<Hero>, connection: db::Connection) -> Json<Hero> { | |
| let insert = Hero { id: None, ..hero.into_inner() }; | |
| Json(Hero::create(insert, &connection)) | |
| } | |
| #[get("/")] | |
| fn read(connection: db::Connection) -> Json<Value> { | |
| Json(json!(Hero::read(&connection))) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div> | |
| <span>1</span> | |
| <span><a href="?p=1">2</a></span> | |
| <span><a href="?p=2">3</a></span> | |
| <span><a href="?p=3">4</a></span> | |
| <span><a href="?p=4">5</a></span> | |
| ... | |
| <span><a href="?p=1">next ›</a></span> | |
| <span><a href="?p=9">last »</a></span> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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 .'">« first</a></span>'; | |
| $r[] = '<span><a href="'. $url . ( $page - 1 ) .'">‹ previous</a></span>'; | |
| $r[] = ( ($range_start > 1) ? ' ... ' : '' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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}'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $databases['drupal6']['default'] = array( | |
| 'driver' => 'mysql', | |
| 'database' => 'database', | |
| 'username' => 'username', | |
| 'password' => 'password', | |
| 'host' => 'hostname', | |
| 'prefix' => '', | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use cpu::Cpu; | |
| use display::Display; | |
| use keypad::Keypad; | |
| pub struct System { | |
| cpu: Cpu, | |
| memory: [u8; 4096], | |
| keypad: Keypad, | |
| display: Display | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |