Redis is my favourite key/value store; it’s flexible, easy to set up and insanely fast. [EventMachine][] is a popular Ruby library for doing asynchronous I/O using an event loop. Bindings already [exist][em-redis] for accessing a Redis server using EM’s async-I/O (courtesy of Jonathan Broad), but unfortunately the resulting code has to use [Continuation-Passing Style][cps] via Ruby blocks. A very basic example of what that looks like follows:
This file contains hidden or 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
| #pragma mark - Phone Number Field Formatting | |
| // Adopted from: http://stackoverflow.com/questions/6052966/phone-number-formatting | |
| - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string | |
| { | |
| if (textField == self.mobileNumberField || textField == self.homeNumberField || textField == self.workNumberField) { | |
| int length = [self getLength:textField.text]; | |
| if(length == 10) { | |
| if(range.length == 0) |
This file contains hidden or 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
| class ApplicationController < ActionController::Base | |
| protect_from_forgery | |
| protected | |
| def current_user | |
| @current_user ||= User.find_by_id(session[:user_id]) | |
| end | |
| def signed_in? |
This file contains hidden or 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
| require 'zmq' | |
| context = ZMQ::Context.new | |
| pub = context.socket ZMQ::PUB | |
| pub.setsockopt ZMQ::IDENTITY, 'ping-pinger' | |
| pub.bind 'tcp://*:5555' | |
| i=0 | |
| loop do | |
| pub.send "ping pinger #{i+=1}" ; sleep 1 | |
| end |
This file contains hidden or 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
| # A sample Gemfile | |
| source "http://rubygems.org" | |
| gem "redis" | |
| gem 'eventmachine', :git => 'git://github.com/eventmachine/eventmachine.git' | |
| gem "em-hiredis" | |
| # gem "em-synchrony" | |
| gem "em-websocket" |
This file contains hidden or 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
| STDOUT.sync = true | |
| require 'queue' | |
| start_time = Time.now.to_i | |
| msg = 0 | |
| queue = Queue.new("testing") | |
| queue.subscribe do |obj| | |
| msg += 1 |
This file contains hidden or 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
| Here is a sample of how I am currently dealing with users. | |
| Big thanks to uggedal! I used his user states as an example: https://github.com/uggedal/states | |
| ### | |
| # How to create password hashes | |
| ### | |
| python -c "import crypt; print crypt.crypt('password', '\$6\$SALTsalt\$')" | |
| ### |
Wes Winham [email protected]
There are many tutorials floating around the web that almost get you a dynamic VPN in EC2. The goal of this tutorial is to be a one-stop-shop for this specific setup.
This file contains hidden or 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
| - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay | |
| { | |
| if ([overlay isKindOfClass:[MKPolygon class]]) | |
| { | |
| MKPolygonView* aView = [[MKPolygonView alloc]initWithPolygon:(MKPolygon*)overlay]; | |
| aView.fillColor = [[UIColor cyanColor] colorWithAlphaComponent:0.2]; | |
| aView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.7]; | |
| aView.lineWidth = 3; | |
| return aView; | |
| } |
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Leaflet</title> | |
| <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.3.1/leaflet.css" /> | |
| <script src="http://cdn.leafletjs.com/leaflet-0.3.1/leaflet.js"></script> | |
| <script src="http://maps.google.com/maps/api/js?v=3.2&sensor=false"></script> | |
| <script src="http://matchingnotes.com/javascripts/leaflet-google.js"></script> | |
| </head> | |
| <body> |