Skip to content

Instantly share code, notes, and snippets.

View jeremyjs's full-sized avatar

Jeremy Meyer jeremyjs

  • San Francisco, CA
View GitHub Profile

CONSTANT_NAME variable_name ClassName functionName

  1. Naming things is cheap--have DESCRIPTIVE NAMES. It should read as close to natural language as possible, avoiding abbrevs. and in-house language when possible.

  2. Functions should have one thing they do. Endeavor to have pure functions, so that they do not have side effects. Functions should be have a maximum of three arguments. Good functions have one or two.

  3. Avoid being clever and implicit whenever possible.

class Thing
def initialize
@phase = 1
@values = [7, 11]
@other_values = [2, 3, 12]
end
def do_it
going = true
while going
# Developers are a tricksey bunch. Name some reasons why you shouldn't just trust the person who wrote the code.
# Name some mental pitfalls that you should watch out for when testing code.
# So then, why shouldn't we be satisfied with testing our own code?
When writing code, it is often hard to see the code from an unbiased perspective.
I can't know exactly what another person who is seeing this code for the first
time will think, or if they will be able to understand it. And I can't think of
everything that might go wrong either. I just spent time making it work a certian
way and have pidgeonholed myself into a certain way of thinking. It's much easier
to get some fresh eyes on the code than it is for me to try to make up for my own
# replace characters in a string
s = "string"
puts s.tr('i', 'o')
puts s.tr('string', 'Heroku')
puts s.tr_s('ri', 'u')
$ ruby -e 'sleep 1 while true' &
[1] 80604
$ fg %1
[1] + 80604 running ruby -e 'sleep 1 while true'
^Z
[1] + 80604 suspended ruby -e 'sleep 1 while true'
$ ps
PID TTY TIME CMD
# check current free space
$ df -h
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
/dev/disk0s2 233Gi 74Gi 158Gi 32% 19571865 41464807 32% /
devfs 221Ki 221Ki 0Bi 100% 767 0 100% /dev
map -hosts 0Bi 0Bi 0Bi 100% 0 0 100% /net
map auto_home 0Bi 0Bi 0Bi 100% 0 0 100% /home
/dev/disk1s2 8.0Mi 1.9Mi 6.1Mi 24% 481 1557 24% /Volumes/Adobe Reader Installer
/dev/disk2s2 3.7Mi 1.9Mi 1.9Mi 50% 477 480 50% /Volumes/SDL
/dev/disk3s2 11Mi 7.8Mi 2.9Mi 74% 1993 730 73% /Volumes/SDL2_mixer
# why is sudo necessary?
to run commands that affect the entire system, or exist outside of any
particular user's home directory
# why is sudo dangerous?
Using sudo, it's possible to delete vital files, directories, or even your
entire system. e.g. "sudo rm -rf /" Don't try this at home. Essentially any
command which is non-reversible is potentially dangerous.
# Create file
$ touch /tmp/file.tmp
$ l /tmp/file.tmp
-rw-r--r-- 1 jmeyer1 wheel 0B Jun 16 15:59 /tmp/file.tmp
# Change owner to root
$ sudo chown root /tmp/file.tmp
$ l /tmp/file.tmp
-rw-r--r-- 1 root wheel 0B Jun 16 15:59 /tmp/file.tmp
$ touch jmeyer.txt
$ scp jmeyer.txt cnuapp@vor.dev.cashnetusa.com:/tmp
The authenticity of host 'vor.dev.cashnetusa.com (10.10.212.130)' can't be established.
RSA key fingerprint is 12:05:3d:8c:37:bf:a6:97:4e:e4:d8:ee:33:d1:19:15.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'vor.dev.cashnetusa.com,10.10.212.130' (RSA) to the list of known hosts.
cnuapp@vor.dev.cashnetusa.com's password:
jmeyer.txt 100% 0 0.0KB/s 00:00
$ rm jmeyer.txt
# view environment variables
$ printenv
PATH=/usr/local/heroku/bin:/usr/local/heroku/bin:/Users/jmeyer1/.rbenv/bin:/Users/jmeyer1/code/8b/bin:/Users/jmeyer1/.rbenv/shims:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
TMPDIR=/var/folders/wz/v_ty7wz108v3tz90gg627nt40000gp/T/
SHELL=/bin/zsh
HOME=/Users/jmeyer1
USER=jmeyer1
LOGNAME=jmeyer1
SSH_AUTH_SOCK=/tmp/launch-E2mZnk/Listeners
Apple_PubSub_Socket_Render=/tmp/launch-GhVrOe/Render