Skip to content

Instantly share code, notes, and snippets.

View CrowdHailer's full-sized avatar

Peter Saxton CrowdHailer

View GitHub Profile
@CrowdHailer
CrowdHailer / list
Last active August 29, 2015 14:08
Padrino Demo applications
- postgreSQL database example. just create action limit to 5 heroku clear db testing
- form object Money Gem or
- Presenter object, geokit and googlemaps
- Flash, flash now
- Error Handling
- views
- sass scut pure
- Crud two - heroku -datetime category form for
- Mailer
- Service objects
@CrowdHailer
CrowdHailer / command don't query
Last active August 29, 2015 14:11
Tell don't ask and service objects
gist
@CrowdHailer
CrowdHailer / first.rb
Created January 21, 2015 01:11
Some fun with ruby currying
class Fixnum
alias_method :times, :*
def *(o=nil)
o.nil? ? ->(x){ times x } : times(o)
end
end
puts (11..14).map(&3.*)

Contract Killer

The popular open-source contract for web designers and developers by Stuff & Nonsense

  • Originally published: 23/12/2008
  • Revised date: 15/12/2013
  • Original post

@CrowdHailer
CrowdHailer / orientation-speed.html
Created June 1, 2015 13:08
Check how often request animation frame is called compaired to device orientation
<script>
var i = 0
var deviceOrientationData
window.addEventListener('deviceorientation', function( event ) {
deviceOrientationData = event;
i = i + 1
}, false);
function AddCount() {
@CrowdHailer
CrowdHailer / create_post.rb
Created August 15, 2015 12:17
Enforcing an interface in Ruby
class CreatePost
# An interactor to create a post.
# Initialize with a request object that implements the request interface for this interactor.
def initialize(request)
RequestInterface.required_on! request
@user = {:title => request.title}
end
def result
@CrowdHailer
CrowdHailer / user.exs
Created September 18, 2015 14:20
Creating stateful module in elixir
# Using the erlang mechanism of tuple modules it is possible to create a "stateful module".
# This concept of a stateful module is discussed in "Programming erlang" Second edition.
defmodule User do
defstruct name: nil, admin: false, internal: "kinda private"
def new(name, options \\ []) do
dependencies = struct(%__MODULE__{name: name}, options)
{__MODULE__, dependencies}
@CrowdHailer
CrowdHailer / clock.ex
Created September 30, 2015 15:04
Creating boundary modules for elixir applications. These have their implementation set during the configuration step. In this example we switch clock between system clock and a dummy clock
# This module represents a behaviour and when used picks from the Application configuration which implementation will be used
defmodule Clock do
@callback now() :: Integer.t
defmacro __using__([]) do
module = Application.get_env(:my_app, :Clock)
quote do
alias unquote(module), as: Clock
end
@CrowdHailer
CrowdHailer / actor.js
Last active March 23, 2021 10:43
Implementing actors in JavaScript.
// Turns out this was not too difficult.
// By using the event loop as a global mail box ordering is even guaranteed for messages between only two actors.
// TODO would like to try and put one actor in a web worker to get some real parallism
// TODO would like to handle errors and have the concept of a deceased actor while a reference to an actor still exists. Probably involves creating an actor system like in Scala. Eurgh.
var actor = {
send: function(message) {
var self = this;
console.log("sending to:", self);
setTimeout(function(){
@CrowdHailer
CrowdHailer / lib.rs
Last active December 6, 2018 18:29
Raxx in Rust
pub mod raxx {
#[derive(Debug)]
pub enum Method {GET, POST}
#[derive(Debug)]
pub struct Request {
pub method: Method
}
#[derive(Debug, PartialEq)]
pub struct Response {