This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
some_var = "false" | |
another_var = "nil" | |
case | |
when some_var == "pink elephant" | |
puts "Don't think about the pink elephant!" | |
when another_var.nil? | |
puts "Question mark in the method name?" | |
else | |
puts "I guess nothing matched... But why?" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Grab 23 random elements between 0 and 10000 | |
arr = (1..10000).to_a.sample(23) | |
p arr | |
# This selects only elements that when divided by 3 have a remainder of 0 | |
# using the % (modulus) operator | |
p arr.select { |element| element % 3 == 0 } | |
# Using `reject` method filter out anything less than 5000 | |
# and use `sort` and `reverse` methods to sort in descending order |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
#have a first_name and last_name attribute with public accessors | |
#attr_accessor | |
attr_accessor :first_name, :last_name | |
#have a class attribute called `people` that holds an array of objects | |
@@people = [] | |
#have an `initialize` method to initialize each instance |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You manipulate postgres through the user postgres, as so: | |
# su - postgres | |
$ createdb mydb | |
$ psql -s mydb | |
# create user someuser password 'somepassword'; | |
# GRANT ALL PRIVILEGES ON DATABASE mydb TO someuser; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kill -9 $(lsof -i tcp:3000 -t) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Meteor files to ignore now handled by .ignore file within .Meteor folder automatically | |
# settings file to ignore to protect API keys | |
settings.json | |
# MUP / MUPX file to ignore to protect server passwords and sensitive info. | |
mup.json | |
# npm package files to ignore | |
node?modules/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cities = ['Dublin', 'Amsterdam', 'Helsinki', 'London'] | |
# Bad way to to walk trough the list print them and their location on the list | |
i = 0 | |
for city in cities: | |
print(i, city) | |
i += 1 | |
# Good way is to use enumerate function. | |
# Enumerate documentation at: https://docs.python.org/3/library/functions.html#enumerate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ps aux | grep -i runserver | |
kill (pid) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import pprint | |
# opens csv file and assingns it to an object | |
with open('data-text.csv') as csvfile: | |
# Use Sniffer to figure out csv dialect | |
dialect = csv.Sniffer().sniff(csvfile.read(1024)) | |
csvfile.seek(0) | |
# pass the dialect to filereader to read the file | |
reader = csv.reader(csvfile, dialect) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
OlderNewer