Skip to content

Instantly share code, notes, and snippets.

View paulghaddad's full-sized avatar

Paul Haddad paulghaddad

View GitHub Profile
@paulghaddad
paulghaddad / gist:0e33ed80956123e60652
Last active August 29, 2015 14:07
Level UP 1: Transferring Files Between Boxes
# SSH into remote host
ssh cnuapp@local.dev.cashnetusa.com
# SCP text file to remote host's tmp directory
scp phaddad.txt cnuapp@local.dev.cashnetusa.com:/tmp
# Delete local copy
@paulghaddad
paulghaddad / gist:5fe0e09a3bbedc9778af
Created October 13, 2014 16:11
Level Up 1: Understands Unix file permissions
1. Use touch to create a new file in the /tmp directory. What permissions do user / group / and world have to that file by default?
cd /tmp
touch new_file.txt
# The permissions of user, group and world are:
user: read, write
group: read
world: read
@paulghaddad
paulghaddad / gist:e28d9ba24927c2ee061b
Created October 13, 2014 20:38
Level Up 1: Can use htop / df / du to monitor system resources
1. Demonstrate the command to check what the remaining disk space is on your laptop. Make sure to use the flag to make the output more readable.
df -h
2. Navigate to the your home directory, and demonstrate the command to see how much space that directory and each subdirectory takes on disk.
du ~
du -d 2 ~ (for a depth of 2)
3. Demonstrate the command to see how much memory is currently being consumed on your laptop. Sort the running processes to see which is consuming the most resources.
@paulghaddad
paulghaddad / gist:ce8b273f10cc8e9fa4db
Created October 13, 2014 21:29
Level Up 1: Knows what ports are and can use netstat to find them
1. Demonstrate the command to show the list of currently listening ports on your laptop.
netstat -l
2. Do it again on a Linux VM, but make sure to include the flags to display the applications that are listening. Find the application port and pid that run sshd.
My VM uses SSH: netstat -alp | grep 'ssh'
tcp 0 0 192.168.56.78:22 192.168.56.1:54924 ESTABLISHED 5591/sshd: cnuapp
@paulghaddad
paulghaddad / gist:c3b7cb782fabe11bb570
Created October 14, 2014 13:50
Level Up 1: Can use ps to find daemon processes
1. If you run the command `ruby -e 'sleep 1 while true'`, you'll start a ruby process that never completes. Try it out and verify that the command never returns. Use the keyboard command to kill it.
Used ctr-c to kill the job
2. Try it again, but append the character that causes the process to run in the background.
ruby -e 'sleep 1 while true' &
3. Use the terminal command to bring it back to the foreground, then use the two keyboard commands to return it to the background.
@paulghaddad
paulghaddad / gist:9a6ab481d4a98e6a2b0e
Created October 14, 2014 15:38
Level Up 1: Understands init scripts and can use init.d to start and stop services
1. On a Linux development VM, use init scripts to restart sshd. Y'know, just in case.
sshd requires execution with an absolute path, so use,'which sshd' to find the path: /usr/sbin/sshd
sudo service ssh start
sudo service ssh restart
2. Let's pretend you just changed your nginx config, and want to reload the changes without stopping the service altogether. Invoke the init script without any arguments to see valid choices. Now run the correct init command to parse and load the config without stopping the server.
sudo service nginx reload
@paulghaddad
paulghaddad / gist:055772fbe584ce4c6d7c
Created October 14, 2014 18:24
Level Up 1: Can check firewall settings with iptables
1. On your development machine, see what rules are currently loaded in the firewall. If it's not running, shame on you, start it first.
To view the current rules: sudo iptables -L
2. Explain why a whitelist approach is better than a blacklist approach for firewalls?
A whitelist is better because a blacklist won't block a threat that is unknown before the attack. With the whitelist approach, it would be blocked by default.
@paulghaddad
paulghaddad / gist:a39a1eac55fd8173959d
Last active August 29, 2015 14:07
Level Up 2: Knows how to find documentation for Ruby and Rails classes
Ruby core has so many more methods than you'll ever keep in your head. That's totally fine, but you need to know how to look up and use those functions. Use the ruby docs to find the docs for the String class. There's a method that lets you substitute a bunch of characters for a corresponding set of characters (it's not gsub). Find that method and use it in a code sample.
"My name is Paul Haddad, and I am from Columbus!".sub(/Columbus/, 'Chicago')
=> "My name is Paul Haddad, and I am from Chicago!"
@paulghaddad
paulghaddad / README.md
Last active August 29, 2015 14:07
Exercism.io: Hamming Exercise

Hamming

Write a program that can calculate the Hamming difference between two DNA strands.

A mutation is simply a mistake that occurs during the creation or copying of a nucleic acid, in particular DNA. Because nucleic acids are vital to cellular functions, mutations tend to cause a ripple effect throughout the cell. Although mutations are technically mistakes, a very rare mutation may equip the cell with a beneficial attribute. In fact, the macro effects of evolution are attributable by the accumulated

@paulghaddad
paulghaddad / gist:496abca04243ecb88bde
Last active August 29, 2015 14:08
Level Up 2: Knows what the five second rule for code review is
1. Explain how the Five Second Rule for code review works.
Code should be written so that it can be understood within five seconds,
principally by the person doing the review. But also by the author of the
code in the future. In either case, if the five second rule isn't met, the
code is likely too complex, and should be simplified.