Skip to content

Instantly share code, notes, and snippets.

@alexedwards
alexedwards / gist:827bae50710c32ab7997
Last active August 29, 2015 14:04
Examples of passing information to a handler via closures in Go
package main
import (
"log"
"net/http"
"time"
)
func main() {
mux := http.NewServeMux()
function find($id)
{
$query = $this->db->where($this->primary_key, $id)
->get($this->table);
if ($query->num_rows() == 1)
{
return $query->row();
}
protected $authentication = 'none'; // Can be 'none', 'basic' or 'digest'
protected $username = FALSE;
protected $password = FALSE;
protected $key = FALSE;
protected $format = 'html';
protected $supported_formats = array(
'html' => 'text/html',
'php' => 'text/plain',
<?php define('BASEPATH', TRUE); include('libraries/snippt.php');
class example extends snippt
{
function index()
{
$data = array(
'message' => 'Hello world!',
'time' => date('D, jS F y - h:i a')
);
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Simple Password - Returns a simple pronouncable passphrase.
Examples: Motir27, Wesag97, Muvak41
Rated as 'good' by http://www.passwordmeter.com/
@access public
@return string
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function simple_password() {
<?php
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// VARIOUS FIND FUNCTIONS
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function find($id)
{
$query = $this->db->where($this->primary_key, $id)
->get($this->table);
if ARGV.include?('--help')
File.read(__FILE__).split("\n").grep(/^# /).each do |line|
puts line[2..-1]
end
exit 0
end
require 'rdiscount'
STDOUT.write(RDiscount.new(ARGF.read).to_html)
@alexedwards
alexedwards / app.rb
Created January 24, 2013 09:41
Ajax content loading with Sinatra, jQuery and HTML5 Pushstate.
require 'sinatra'
before do
response['Cache-Control'] = 'no-cache, no-store' if request.xhr?
end
get '/' do
erb :home, layout: ! request.xhr?
end
@alexedwards
alexedwards / app.rb
Created January 24, 2013 09:42
Ajax content loading with Sinatra, jQuery and HTML5 Pushstate.
require 'sinatra'
before do
response['Cache-Control'] = 'no-cache, no-store' if request.xhr?
end
get '/' do
erb :home, layout: ! request.xhr?
end
@alexedwards
alexedwards / app.rb
Created January 24, 2013 09:42
Ajax content loading with Sinatra, jQuery and HTML5 Pushstate.
require 'sinatra'
before do
response['Cache-Control'] = 'no-cache, no-store' if request.xhr?
end
get '/' do
erb :home, layout: ! request.xhr?
end