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
| // a better name would be - if predicate is True then success, else not success. | |
| // using basic logic we can now create logic functions that compute only as much as required | |
| // anyBool :: (a -> Bool) -> Bool -> [a] -> Bool | |
| function anyBool(pred,success,xs) { | |
| for (var i = 0; i < xs.length; i++) { | |
| if (pred(xs[i]) === success) { | |
| return success }} | |
| return !success } |
| // see blog post: http://www.hiddentao.com/archives/2013/07/08/generate-overridable-getters-and-setters-in-javascript/ | |
| Function.prototype.generateProperty = function(name, options) { | |
| // internal member variable name | |
| var privateName = '__' + name; | |
| options = options || {}; | |
| options.get = ('undefined' === typeof options.get ? true : options.get ); | |
| options.set = ('undefined' === typeof options.set ? true : options.set ); | |
| // pre-initialise the internal variable? |
| class ActionDispatch::Routing::Mapper | |
| def draw(routes_name) | |
| instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb"))) | |
| end | |
| end | |
| BCX::Application.routes.draw do | |
| draw :api | |
| draw :account | |
| draw :session |
Some exercises from the Falsy Values workshops.
The good parts:
| // If you're a glutton for punishment, and/or claim | |
| // that JavaScript libraries have too much "bloat", | |
| // use this to force yourself to write JS longhand. | |
| (function(window) { | |
| function screwed() { | |
| window._ = null; | |
| window.$ = null; | |
| window.$A = null; | |
| window.$F = null; |
| // Original code from http://www.blog.highub.com/mobile-2/a-fix-for-iphone-viewport-scale-bug/ | |
| var metas = document.getElementsByTagName('meta'); | |
| var i; | |
| if (navigator.userAgent.match(/iPhone/i)) { | |
| for (i=0; i<metas.length; i++) { | |
| if (metas[i].name == "viewport") { | |
| metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0"; | |
| } | |
| } |
| /** | |
| * Annoying.js - How to be an asshole to your users | |
| * | |
| * DO NOT EVER, EVER USE THIS. | |
| * | |
| * Copyright (c) 2011 Kilian Valkhof (kilianvalkhof.com) | |
| * Visit https://gist.github.com/767982 for more information and changelogs. | |
| * Visit http://kilianvalkhof.com/2011/javascript/annoying-js-how-to-be-an-asshole/ for the introduction and weblog | |
| * Check out https://gist.github.com/942745 if you want to annoy developer instead of visitors | |
| * |
| # Enable upload_progress module for easy cross browser progress bar support | |
| # using only javascript client side | |
| upload_progress foobar_uploads 1m; | |
| server { | |
| # We only need one server block to deal with HTTP and HTTPS | |
| # avoids duplication | |
| listen 80; | |
| listen 443 default ssl; | |
| # NOTICE: to get Nginx+Unicorn best-practices configuration see the gist https://gist.github.com/3052776 | |
| $ cd /usr/src | |
| $ wget http://nginx.org/download/nginx-1.2.1.tar.gz | |
| $ tar xzvf ./nginx-1.2.1.tar.gz && rm -f ./nginx-1.2.1.tar.gz | |
| $ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz | |
| $ tar xzvf pcre-8.30.tar.gz && rm -f ./pcre-8.30.tar.gz | |
| $ wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz |