Skip to content

Instantly share code, notes, and snippets.

View pinkopaque22's full-sized avatar

Patricia Ehrhardt pinkopaque22

View GitHub Profile
dailykos git:(release) dk-dev
Didn't detect any host file entries for dailykosdev.com.
It's possible that your router will not correctly resolve dailykosdev.com entries which will prevent the devenv from running.
For more info, see the getting started documentation under 'Cannot resolve...'.
No arguments given, assuming you want to start.
14:24:47 dk4 | direnv: loading ~/src/dk4-perl/.envrc
14:24:47 dk4-s3 | direnv: loading ~/src/dk4-perl/.envrc
14:24:47 dk4 | direnv: using nix
#require 'open_uri_redirections'
require 'open-uri'
require 'nokogiri'
cities = ['sanfrancisco', 'seattle']
search_terms = ['ruby', 'python', 'react', 'java']
cities.each do |city|
search_terms.each do |search_term|
url = "https://#{city}.craigslist.org/search/cpg?query=#{search_term}&is_paid=all"
@pinkopaque22
pinkopaque22 / binary_tree.rb
Created May 4, 2016 23:02
Binary Search Tree w/out Recursion
The "BST In-Order Traversal" Problem
Given a binary search tree, produce an in-order list of all keys in the tree without using recursion.
Explain and code an efficient solution. Analyze the time and space complexities.
Follow Up Problem:
Same problem as above but this time you also can't use a stack or any additional memory besides the tree.
class BinarySearchTree
attr_accessor :data, :left, :right
//////Problem/////
Tube strike options calculator
The sweaty bus ride
There is a tube strike today so instead of getting the London Underground home you have decided to take the bus. It's a hot day and you have been sitting on the bus for over an hour, but the bus is hardly moving. Your arm is sticking to the window and sweat drips off your nose as you try to read your neighbour's book when you say to yourself, "This is ridiculous. I could have walked faster than this!" Suddenly you have an idea for an app that helps people decide whether to walk or take the bus home when the London Underground is on strike.
You rush home (relatively speaking) and begin to define the function that will underpin your app.
Function specification
You must create a function which takes three parameters; walking distance home, distance the bus must travel, and the combined distance of walking from the office to the bus stop and from the bus stop to your house. All distances are in kilometres.
So for example, if your home is 5km a
/////Problem/////
You are going to be given a word. Your job will be to make sure that each character in that word has the exact same number of occurrences. You will return true if it is valid, or false if it is not.
For example:
"abcabc" is a valid word because 'a' appears twice, 'b' appears twice, and'c' appears twice.
"abcabcd" is NOT a valid word because 'a' appears twice, 'b' appears twice, 'c' appears twice, but 'd' only appears once!
"123abc!" is a valid word because all of the characters only appear once in the word.
For this kata, capitals are considered the same as lowercase letters. Therefore: 'A' == 'a' .
@pinkopaque22
pinkopaque22 / character_counter.rb
Created March 20, 2016 19:19
Codewars Solution to Character Counter in Ruby
CHARACTER COUNTER
You are going to be given a word. Your job will be to make sure that each character in that word has the exact same number of occurrences. You will return true if it is valid, or false if it is not.
For example:
"abcabc" is a valid word because 'a' appears twice, 'b' appears twice, and'c'appears twice.
"abcabcd" is NOT a valid word because 'a' appears twice, 'b' appears twice,'c' appears twice, but 'd' only appears once!
"123abc!" is a valid word because all of the characters only appear once in the word.
For this kata, capitals are considered the same as lowercase letters. Therefore: 'A' == 'a' .
INPUT
@pinkopaque22
pinkopaque22 / most_frequent_item_count.rb
Last active March 20, 2016 19:16
Codewars Solution for Most Frequent Item Count in Ruby
MOST FREQUENT ITEM COUNT
Write a program to find count of the most frequent item of an array.
Assume that input is array of integers.
Ex.:
input array: [3, -1, -1, -1, 2, 3, -1, 3, -1, 2, 4, 9, 3]
ouptut: 5
@pinkopaque22
pinkopaque22 / most_frequent_item_count.py
Last active March 20, 2016 19:25
Solution for Codewars Most Frequent Item Count in Python
//Codewars Kata Level 7 (easy)//
MOST FREQUENT ITEM COUNT
Write a program to find count of the most frequent item of an array.
Assume that input is array of integers.
Ex.:
input array: [3, -1, -1, -1, 2, 3, -1, 3, -1, 2, 4, 9, 3]
ouptut: 5
Most frequent number in example array is -1. It occures 5 times in input array.
@pinkopaque22
pinkopaque22 / Good Parents
Created December 19, 2015 07:18
Ruby's Advanced Classes
Parent classes should be as generic as possible. That is, they should be able to describe a broad range of things. A simple example of a class that lends itself to parenthood is a class named Dog. The purpose of this class will be to define the general attributes and behavior that all dogs share, regardless of breed. Attributes like having a name, four legs, two eyes, and a tail are shared amongst all dog breeds. Behavior like eating, sleeping, and barking are also shared amongst all dog breeds.
Let's take a look at inheritance in action by defining a Dog class. First we'll initialize the Dog class with a name attribute:
class Dog
attr_accessor :name
def initialize(name)
@name = name
@pinkopaque22
pinkopaque22 / Hashes-Hash Methods
Created December 18, 2015 00:21
Hashes in Ruby-Exercises
__Details__
This exercise will help you get familiar with some common Hash methods that Ruby provides.
merge_us method
Create a method named merge_us that expects two arguments and combines them, assuming they're hashes. The Hash class has a method named merge that will be helpful to you.
my_keys method
Create a method named my_keys that takes a hash argument and returns an Array of its keys. The Hash class has a method named keys that will be helpful to you.
do_i_have? method