Skip to content

Instantly share code, notes, and snippets.

View garybernhardt's full-sized avatar

Gary Bernhardt garybernhardt

View GitHub Profile

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.

#!/usr/bin/env bash
set -e
if [ -e static ]; then
rm -r static
fi
mkdir -p static
sass src/sass/main.scss > static/application.css
$(npm bin)/browserify src/js/main.js > static/application.js
from collections import namedtuple
from datetime import date
# Here's a user defined using the usual "OO" style.
class UserClass:
def __init__(self, first, last, birthday):
self.__first = first
self.__last = last
self.__birthday = birthday
$ heroku pg:backups
Installing Heroku Toolbelt v4... done.
For more information on Toolbelt v4: https://github.com/heroku/heroku-cli
Setting up node-v4.1.1... done
Installing core plugins heroku-cli-addons, heroku-apps, heroku-fork, heroku-git, heroku-local, heroku-run, heroku-status...
Error reading plugin: heroku-apps. See /Users/grb/.heroku/error.log for more information.
Error reading plugin: heroku-cli-addons. See /Users/grb/.heroku/error.log for more information.
Error reading plugin: heroku-fork. See /Users/grb/.heroku/error.log for more information.
Error reading plugin: heroku-git. See /Users/grb/.heroku/error.log for more information.
failbowl:~(master) $ curl 'http://maps.google.com/?saddr=St.%20Petersburg%20Shavrova%2015&daddr=St.%20Petersburg%20Sadovaya%2030&dirflg=r&output=json'
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://maps.google.com/maps?saddr=St.%20Petersburg%20Shavrova%2015&amp;daddr=St.%20Petersburg%20Sadovaya%2030&amp;dirflg=r&amp;output=json">here</A>.
</BODY></HTML>
failbowl:~(master) $ curl 'http://maps.google.com/maps?saddr=St.%20Petersburg%20Shavrova%2015&amp;daddr=St.%20Petersburg%20Sadovaya%2030&amp;dirflg=r&amp;output=json'
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
CyBurTaz: i programed my comps memory to read my own lang
RAVERgrl34: LoL... oh muh god!
CyBurTaz: FOXXY STFU
RAVERgrl34: you are a piece of shit!
RAVERgrl34: ROFL
RAVERgrl34: LMAO
RAVERgrl34: oh muh god!
RAVERgrl34: you are lamest mother fucking i have ever seen!
RAVERgrl34: oh muh god, you are lame.
def adjust(t,h);(3*h)−(4*t*h);end
def adjust(t,h);(3*h)-(4*t*h);end

Things that programmers don't know but should

(A book that I might eventually write!)

Gary Bernhardt

I imagine each of these chapters being about 2,000 words, making the whole book about the size of a small novel. For comparison, articles in large papers like the New York Times average about 1,200 words. Each topic gets whatever level of detail I can fit into that space. For simple topics, that's a lot of space: I can probably walk through a very basic, but working, implementation of the IP protocol.

module TwitterLib
def self.authenticate
libs = [Twitter, TweetStream]
libs.each do |lib|
lib.configure do |config|
config.consumer_key = ENV.fetch("TWITTER_CONSUMER_KEY")
config.consumer_secret = ENV.fetch("TWITTER_CONSUMER_SECRET")
config.oauth_token = ENV.fetch("TWITTER_OAUTH_TOKEN")
config.oauth_token_secret = ENV.fetch("TWITTER_OAUTH_SECRET")
end
# This is a stripped-down example based on Selecta's TTY handling. We store the
# TTY state in `tty_state`, then go into an infinite loop. When the loop is
# terminated by a ^C, we try to restore the TTY state. It's important that this
# work, but it doesn't in some subtle situations, and I don't know why.
#
# Save this file as test.rb and run it via this command, where `stty` should
# successfully restore the TTY state:
# bash -c 'echo | ruby test.rb'
#
# Next, run it via this command, where `stty` should fail to restore the TTY