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
#[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
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
use std::ops::Deref; | |
use rocket::http::Status; | |
use rocket::request::{self, FromRequest}; | |
use rocket::{Request, State, Outcome}; | |
use r2d2; | |
use r2d2_diesel::ConnectionManager; | |
use diesel::mysql::MysqlConnection; |
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
<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
var server = require('websocket').server, http = require('http'); | |
var socket = new server({ | |
httpServer: http.createServer().listen(1337) | |
}); | |
socket.on('request', function(request) { | |
var connection = request.accept(null, request.origin); | |
connection.on('message', 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
// when a user clicks one of our links | |
$('a').click(function (e) { | |
// Detect if pushState is available | |
if (history.pushState) { | |
history.pushState(null, null, $(this).attr('data-location')); // URL is now /inbox/N | |
// showMailItem(); // example function to do something based on link clicked | |
} | |
return false; |
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
-- This file should undo anything in `up.sql` | |
DROP TABLE heroes; |