Skip to content

Instantly share code, notes, and snippets.

@kaiguogit
kaiguogit / tmux.md
Created May 18, 2019 01:42 — forked from andreyvit/tmux.md
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

@kaiguogit
kaiguogit / web-servers.md
Created January 15, 2018 23:46 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
require 'active_support/all'
@candidates = [
{
id: 5,
years_of_experience: 4,
github_points: 293,
languages: ['C', 'Ruby', 'Python', 'Clojure'],
date_applied: 5.days.ago.to_date,
age: 26
# Determine whether a string contains a SIN (Social Insurance Number).
# A SIN is 9 digits and we are assuming that they must have dashes in them
def has_sin?(string)
/\b[0-9]{3}-[0-9]{3}-[0-9]{3}\b/.match(string) != nil
end
puts "has_sin? returns true if it has what looks like a SIN"
puts has_sin?("please don't share this: 234-604-142") == true
puts "has_sin? returns false if it doesn't have a SIN"
def benchmark
# Your benchmarking code goes here.
start_time = Time.now
yield
end_time = Time.now
end_time - start_time
end
# Be careful, pasting this into IRB will take a long time to print.
require "pry-byebug"
@states = {
OR: ['Oregon',['Salem', 'Portland']],
FL: ['Florida',['Tallahassee','Jacksonville']],
CA: ['California',['Sacramento','Los Angeles']],
NY: ['New York',['Albany','New York']],
MI: ['Michigan',['Lansing', 'Detroit']],
WA: ['Wahsington',['Olympia','Seattle']],
IN: ['Indiana',['Boise']]
}
list = {'yvr' => 'Vancouver', 'yba' => 'Banff', 'yyz' => 'Toronto', 'yxx' => 'Abbotsford', 'ybw' => 'Calgary'}
# Why is it returning nil instead of first element of the list above
p list["yvr"]
@kaiguogit
kaiguogit / sort.rb
Last active July 20, 2016 18:29 — forked from davidvandusen/sort.rb
require 'benchmark'
# Sort the array from lowest to highest
def sort(arr)
#bubble sort
return arr if arr.length <= 1
sorted = true
while sorted
sorted = false
(arr.length-1).times do |i|
# Save this file to your computer so you can run it
# via the command line (Terminal) like so:
# $ ruby shakil_the_dog.rb
#
# Your method should wait for user input, which corresponds
# to you saying something to your dog (named Shakil).
# You'll probably want to write other methods, but this
# encapsulates the core dog logic
def shakil_the_dog
# must be baller and either furnished or rent cheaper than 2100
def rent?(furnished, rent, baller)
baller && (furnished || rent < 2100)
end
###
# Add your "test" ("driver") code below in order to "test drive" (run) your method above...
# The test code will call the method with different permutations of options and output the result each time.
# This way, you will be able to run the renter.rb file from the CLI and look at the output of your "tests" to validate if the method works.
# Without the test code, it will be hard for you to know if this method is working as it should or not.