Skip to content

Instantly share code, notes, and snippets.

@sean3z
sean3z / Registry.php
Last active August 9, 2017 00:13
Zephir Zend Registry fill
<?php
/**
* Here we conditionally defined Zend_Registry
* When our custom Zephir module is installed, Zend\Registry becomes available.
* https://github.com/sean3z/zendframework-zephir
*/
if (class_exists('Zend\\Registry')) {
class Zend_Registry extends Zend\Registry {
// No code block needed here since we extend Zend\Registry
@sean3z
sean3z / fetch.js
Last active September 9, 2017 22:41
Basic fetch example
fetch('https://api.chucknorris.io/jokes/random')
.then(response => response.json())
.then(body => {
console.log(body);
});
@sean3z
sean3z / gist:185806fdde8b1d8eae50348dddfb0897
Created October 5, 2017 23:30
Rocket 0.3.3 & Rust 1.22.0-nightly
[sean@lappy486:~] $ wrk -d1m http://localhost:8080/
Running 1m test @ http://localhost:8080/
2 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 133.90us 26.21us 2.64ms 84.63%
Req/Sec 36.23k 1.02k 39.12k 75.58%
4326188 requests in 1.00m, 602.36MB read
Requests/sec: 72103.47
Transfer/sec: 10.04MB
@sean3z
sean3z / gist:23632125fa559e5441767866d6e88ec2
Created October 5, 2017 23:37
Restify 6.0.1 & Node.js 8.6.0
[sean@lappy486:~] $ wrk -d1m http://localhost:8080/
Running 1m test @ http://localhost:8080/
2 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 696.69us 1.47ms 157.02ms 99.76%
Req/Sec 7.53k 1.00k 8.90k 66.58%
898973 requests in 1.00m, 140.60MB read
Requests/sec: 14981.94
Transfer/sec: 2.34MB
@sean3z
sean3z / server.js
Created October 5, 2017 23:42
Restify 6.0.1 Example
"use strict";
const restify = require('restify');
const app = restify.createServer();
app.get('/', (req, res, next) => {
res.send('Hello, world!');
});
app.listen(8080, () => {
@sean3z
sean3z / Cargo.toml
Created March 17, 2018 15:56
Adding serde and rocket_contrib
[package]
name = "hero-api"
version = "0.1.0"
authors = ["sean"]
[dependencies]
rocket = "0.3.6"
rocket_codegen = "0.3.6"
serde = "1.0"
serde_json = "1.0"
@sean3z
sean3z / hero.rs
Last active March 17, 2018 16:10
A first stab at our Hero model
#[derive(Serialize, Deserialize)]
pub struct Hero {
pub id: Option<i32>,
pub name: String,
pub identity: String,
pub hometown: String,
pub age: i32
}
@sean3z
sean3z / main.rs
Last active March 17, 2018 16:28
Adding our Hero endpoints
#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate rocket;
#[macro_use] extern crate rocket_contrib;
#[macro_use] extern crate serde_derive;
use rocket_contrib::{Json, Value};
mod hero;
@sean3z
sean3z / app.js
Created March 18, 2018 02:38
pushState and popstate example using jQuery
// 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;
@sean3z
sean3z / server.js
Created March 18, 2018 02:42
Websocket example (without Socket.io)
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) {