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
#!/bin/sh | |
# | |
backupdir="./pg_backups" | |
pgdump_args="-bF c" | |
pgdumpall_globals_args="" | |
pg_backup() { | |
if [ ! -d ${backupdir} ]; then | |
echo Creating $backupdir |
From: app/serializers/nameserver_serializer.rb @ line 4 NameserverSerializer#attributes: | |
4: def attributes | |
5: hash = super | |
=> 6: binding.pry | |
7: hash | |
8: end | |
1.8.7 (#<NameserverSerializer:0x1102735d8>):0 > object_id | |
=> 2282986220 |
#!/bin/sh | |
# Handle previously empty directory. | |
if [ $1 = 0000000000000000000000000000000000000000 ]; then | |
old=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | |
else | |
old=$1 | |
fi | |
# Touch tmp/restart.txt so Pow will restart the server |
#!/bin/sh | |
# | |
# Makefile wrapper to help GNUMake related RubyGem extensions | |
# build properly on FreeBSD/Solaris. | |
# | |
# Write this file to ~/bin/make | |
# $ chmod 755 ~/bin/make | |
# $ export PATH=$HOME/bin:$PATH | |
# | |
# Can now "gem install" or "bundle install" or whatever you need. |
# abcdefghijklmnopqrstuvwxyz | |
# sn rgh o la m tdyibe | |
def encode(string, key = "abcdefghijklmnopqrstuvwxyz") | |
ord_a = "a".ord | |
string.chars.map do |c| | |
case c | |
when /[a-z]/ | |
n = key.index(c) | |
n ? (n + ord_a).chr : c | |
when /[A-Z]/ |
Some exercises from the Falsy Values workshops.
The good parts:
class Thinger | |
def starts_at=(v) | |
v = DateTime.parse(v, "%m/%d/%Y %h:%M%p") if v.kind_of?(String) | |
write_attribute(:starts_at, v) | |
end | |
end |
class Venue | |
def as_json(options = {}) | |
super(options.merge(:include => [:city])) | |
end | |
end |
# The IP Address Validator accepts the following options | |
# | |
# * allow_nil - allows nil values | |
# * allow_blank - allows blank values | |
# * allow_cidr - allows /prefixlen CIDR masks in values | |
# | |
# the validator will use regular expressions in an attempt to prevent | |
# malformed IP addresses from being passed to the IPAddr.new initializer | |
# as this method can be very slow to raise exceptions for malformed input. | |
class IpAddressValidator < ActiveModel::EachValidator |
require 'net/https' | |
require 'uri' | |
email = ARGV[0] | |
password = ARGV[1] | |
uri = URI.parse("https://google.com/accounts/ClientLogin") | |
req = Net::HTTP::Post.new(uri.path) | |
req.set_form_data({'Email'=> email, 'Passwd' => password,'accountType' => 'GOOGLE', 'service' => 'ac2dm', 'source' => 'myexample'}) |