Skip to content

Instantly share code, notes, and snippets.

@violetaria
violetaria / gist:0d958508888e3fc23119
Created February 23, 2016 19:29
git pre-commit hook
#!/bin/bash
# Pre commit hook that prevents FORBIDDEN code from being commited.
# Add unwanted code to the FORBIDDEN array as necessary
FILES_PATTERN='\.(rb|js|coffee|spec)(\..+)?$'
FORBIDDEN=( debugger ruby-debug binding.pry console.log )
for i in "${FORBIDDEN[@]}"
do
@violetaria
violetaria / commands.md
Created November 4, 2015 20:19
How to Unfuck Postgres for El Capitan users

So, Brit is smart and figured out some dumb stuff

  • El Capitan breaks how Postgres previously loaded and ran ...
  • So basically we have to update homebrew, and then reinstall postgres ...
  1. Run brew update - Pull down the latest changes to homebrew for El Capitan
  2. Run brew upgrade postgres - Update to the latest postgres release in homebrew
  3. Run launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist - Stop the old version of postgres
  4. Run launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist - Start the new postgres database
Normal Mode
- How many users are there?
SQL: SELECT COUNT(*) FROM users;
Answer: 50
- What are the 5 most expensive items?
SQL: SELECT title,price FROM items ORDER BY price DESC LIMIT 5;
Answer:
Small Cotton Gloves|9984
require "pry"
require "set"
word_list = [
"cat", "chick", "duck", "cat", "clown", "brick", "bananas",
"coffee", "totalitarianism", "metacircular", "interpreter",
"wednesday", "ruby", "evaluation", "consternation", "chicanery"
]
MAX_TURNS = 6
player1 = nil
require "pry"
word_list = [
"cat", "chick", "duck", "cat", "clown", "brick", "bananas",
"coffee", "totalitarianism", "metacircular", "interpreter",
"wednesday", "ruby", "evaluation", "consternation", "chicanery"
]
def greeting
puts "--------------------------"
Read the manual page for a unix command with man or woman. What command did you read about? What does it do?
I read about grep which can be used to search inside a file or files for specific text. We talked about it a bit in class but I learned that it can also search for regular expressions. This makes grep an extremely powerful command line tool which allows you to easily find text inside your code.
I've used it before a little at work but not enough to consider myself a "power user." I am interested to learn how often people use this in the Ruby and Rails world.
def destutter(array)
result = [] # Array.new
last_val = nil
array.each do |cur_val|
result.push(cur_val) if(cur_val!=last_val)
last_val = cur_val
end
result
end
randNbr = rand(1...100)
guess = nil
until guess==randNbr
print "Enter a guess: "
guess = gets.chomp.to_i
if(guess < randNbr)
puts "Your guess of #{guess} is too low! Try again."
elsif(guess > randNbr)
puts "Your guess of #{guess} is too high! Try again."