Skip to content

Instantly share code, notes, and snippets.

View jfarmer's full-sized avatar
🐢

Jesse Farmer jfarmer

🐢
View GitHub Profile
@jfarmer
jfarmer / key.md
Created November 22, 2020 05:20
Twitter (un)official Consumer Key

Twitter Official Consumer Key

Twitter for Android

type:            PIN
Consumer key:    3nVuSoBZnx6U4vzUxf5w
Consumer secret: Bcs59EFbbsdF6Sl9Ng71smgStWEGwXXKSjYvPVt7qys

Twitter for iPhone

type:            PIN

Consumer key: IQKbtAYlXLripLGPWd0HUA

@jfarmer
jfarmer / index.html
Last active February 25, 2020 00:46 — forked from keithjng/css
todos
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="./main.css">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TODO List</title>
</head>
<body>
<section>
# Method name: item_counts
# Input: An arbitrary array
#
# Returns: A hash where every item is a key whose value is the number of times
# that item appears in the array
#
# Prints: Nothing
# Version 0.1
# ====================================================
@jfarmer
jfarmer / rot_n_jesse.rb
Last active August 29, 2015 14:05 — forked from Katzy/ROTN
def rot_n_char(char, rot_by)
fail ArgumentError, "First argument must be a 1-letter String (got `#{char}')" unless char.length == 1
case char
when ('a'..'z')
((char.ord - 'a'.ord + rot_by) % 26 + 'a'.ord).chr
when ('A'..'Z')
((char.ord - 'A'.ord + rot_by) % 26 + 'A'.ord).chr
else
char
def textalyzer (string)
file_name = ARGV[0]
string = open(file_name).read
histogram(freq(count(str_char(sanitize(string)))))
return
end
def count (string)

Questions

How do I get it to return per line, isn't that the point of this exercise? For instance, how would I get it to return each value, such as line 35's list "total = 0" on one line, next "total = 0 + 11", next line "total = 11+22".

I could not find a way to do it like, 'running_total = return item[0], return item[0] + item[1]...item[i]'.

First, it's good that you understand what you need to do and are referring to the last item of the list as item[i]. Keep in mind that if the list is in the variable list then to get the item at, say, index 10, we want list[10], not item[10]. Imagine if you could write code like this:

def sum(list)
class GuessingGame
def initialize(answer)
@answer = answer
end
def guess(guess)
@last_guess = guess
if guess == @answer
return :correct
elsif guess < @answer
def times_table(n)
(1..n).each do |row_num|
line = ""
(1..n).each{ |col_num| line += "#{row_num * col_num}\t"}
puts line
end
end
times_table(5)
# Slightly better name, bang (!) to indicate side effects
def process_raw_data!
# See:
# http://po-ru.com/diary/rubys-magic-underscore/
# http://po-ru.com/diary/destructuring-assignment-in-ruby/
self.raw_data.each do |date, name, url, cb_url, funding_type, value|
Company.where(name: name).first_or_create(url: url, cb_url: cb_url)
# See: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#method-c-strptime
Event.where(funding_type: funding_type, date: Date.strptime(date, '%M/%y'), value: value).first_or_create
class GuessingGame
def initialize(answer)
@answer = answer
end
def guess(g)
if @answer < g
return :high