This file contains 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 id="content"></div> | |
<script type="text/javascript"> | |
var content = document.getElementById('content'); | |
var socket = new WebSocket('ws://localhost:1337'); | |
socket.onopen = function () { | |
socket.send('hello from the client'); | |
}; | |
socket.onmessage = function (message) { |
This file contains 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
-- This file should undo anything in `up.sql` | |
DROP TABLE heroes; |
This file contains 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 diesel; | |
use diesel::prelude::*; | |
use diesel::mysql::MysqlConnection; | |
use schema::heroes; | |
#[table_name = "heroes"] | |
#[derive(Serialize, Deserialize, Queryable, Insertable)] | |
pub struct Hero { | |
pub id: Option<i32>, | |
pub name: String, |
This file contains 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
table! { | |
heroes { | |
id -> Nullable<Integer>, | |
name -> Varchar, | |
identity -> Varchar, | |
hometown -> Varchar, | |
age -> Integer, | |
} | |
} |
This file contains 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
#![feature(plugin)] | |
#![plugin(rocket_codegen)] | |
extern crate rocket; | |
#[get("/<name>/<age>")] | |
fn hello(name: String, age: u8) -> String { | |
format!("Hello, {} year old named {}!", age, name) | |
} |
This file contains 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 Hero { | |
pub fn create(hero: Hero, connection: &MysqlConnection) -> Hero { | |
diesel::insert_into(heroes::table) | |
.values(&hero) | |
.execute(connection) | |
.expect("Error creating new hero"); | |
heroes::table.order(heroes::id.desc()).first(connection).unwrap() | |
} |
This file contains 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 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 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 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' => '', | |
); |