This file contains 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
#Newbie programmer | |
def factorial(x): | |
if x == 0: | |
return 1 | |
else: | |
return x * factorial(x - 1) | |
print factorial(6) | |
#First year programmer, studied Pascal |
This file contains 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
#Using csv reader | |
import csv | |
csvreader=csv.reader(open('x.csv','r')) | |
list = [ x[0] for x in csvreader] | |
#Using zip | |
columns = zip(*csvreader) | |
nocolumns=len(columns) | |
This file contains 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
#!/usr/bin/python | |
import codecs | |
import csv | |
try: | |
from cStringIO import StringIO | |
except ImportError: | |
from StringIO import StringIO |
This file contains 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
f = [1, 2, 3, 4, 5, 5, 5, 6] | |
set(f) | |
print list(set(f)) | |
#A set object is an unordered collection of distinct hashable objects. Common uses include membership testing, removing duplicates from a sequence, and computing mathematical operations such as intersection, union, difference, and symmetric difference. | |
This file contains 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
<!DOCTYPE html> | |
<!-- | |
Copyright 2010 Google Inc. | |
All rights reserved. | |
Original slides: | |
Marcin Wichary | |
Modifications: | |
Ernest Delgado | |
Alex Russell |
This file contains 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
require 'rubygems' | |
require 'sinatra' | |
require 'redis' | |
# To use, simply start your Redis server and boot this | |
# example app with: | |
# ruby example_note_keeping_app.rb | |
# | |
# Point your browser to http://localhost:4567 and enjoy! | |
# |
This file contains 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
require 'rubygems' | |
require 'neo4j' | |
include Neo4j | |
Transaction.new | |
# create some people | |
andreas = Node.new :name => 'andreas' | |
peter = Node.new :name => 'peter' | |
kalle = Node.new :name => 'kalle' |
This file contains 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
#Parsing with plain Ruby | |
filename = 'data.csv' | |
file = File.new(filename, 'r') | |
file.each_line("\n") do |row| | |
columns = row.split(",") | |
break if file.lineno > 10 | |
end |
This file contains 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
def csv_to_array(file_location) | |
csv = CSV::parse(File.open(file_location, 'r') {|f| f.read }) | |
fields = csv.shift | |
csv.collect { |record| Hash[*(0..(fields.length - 1)).collect {|index| [fields[index],record[index].to_s] }.flatten ] } | |
end |
This file contains 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
# 1) Put this file in your working directory | |
# 2) run 'sudo gem install active_support grit' | |
# 3) run 'ruby git-line-count.rb' | |
# 4) run 'open loc.html' | |
# 5) yay | |
require 'rubygems' | |
require 'active_support' | |
require 'grit' | |
require 'open-uri' |
OlderNewer