Some exercises from the Falsy Values workshops.
The good parts:
- HTTP server and client in same script
- Express cookies example
- Express routing example
- Express error handling
- Express middlewares example
- Simple HTTP proxy
Some exercises from the Falsy Values workshops.
The good parts:
:+1: | |
:-1: | |
:airplane: | |
:art: | |
:bear: | |
:beer: | |
:bike: | |
:bomb: | |
:book: | |
:bulb: |
#!/usr/bin/python | |
#usage python show.py <local_port> | |
''' | |
Taken from: https://gist.github.com/932137 (found in http://news.ycombinator.com/item?id=2467107 ) | |
Let's say you have a webapp running in localhost (with `manage.py runserver` in django or `ruby script.rb` in sinatra or `rails server` or whatever) and you want others to be able to see it with a public url without deploying remotely. | |
ssh provides a neat facility for that: tunneling. You set up a "tunnel" from the remote host to yours and vice-versa and then you give the remote host's url and it will send all of its requests to your local daemon. |
module MethodCop | |
# Guard methods that have side effects with a callback that fires before the method is invoked. | |
# If the callback returns a "falsey" value, the method is halted and will not be called. | |
# The callback will return nil instead. | |
# if the method does not have side effects or you depend on its return value, you should NOT | |
# use this on that method! This will break the _hell_ out of design by contract. | |
# currently does not work with methods that accept blocks so be aware of that. Fixes, improvements, | |
# pull requests, and general "why on earth did you do this" notes are encouraged. | |
#TODO: DRY this up |
module LikeRuby | |
VALLEYGIRL = %w[omg so like totally right toootally stuff] | |
FRATGUY = %w[friggin fuckin dude man bro broheim broseph] | |
INTERNETS = %w[lol rofl teh ohai plz] | |
SNOOP = %w[yo homey homeboy sup dog shit girl ma biatch ho shiiit] | |
LOCAL = %w[wicked hella anyways] | |
MISC = %w[just hey yeah ok um uh ah actually something] | |
ALLSLANG = VALLEYGIRL + FRATGUY + INTERNETS + SNOOP + LOCAL + MISC | |
def method_missing(name, *args) |
import SimpleHTTPServer | |
class CORSHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): | |
def send_head(self): | |
"""Common code for GET and HEAD commands. | |
This sends the response code and MIME headers. | |
Return value is either a file object (which has to be copied | |
to the outputfile by the caller unless the command was HEAD, | |
and must be closed by the caller under all circumstances), or |
http://guides.rubyonrails.org/migrations.html
var generateRandomBoxes = function() { | |
var $doc = $(".container"); | |
var $bareBox = $("<div class='box' style='position:absolute; border:1px solid black; width:50px;'></div>"); | |
var maxHeight = 200; | |
var height, | |
$box; | |
for (var i = 0; i < 100; i++) { | |
height = Math.floor(Math.random() * maxHeight); | |
$box = $bareBox.clone().css('height', height + 'px') |
Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.
$ python -m SimpleHTTPServer 8000