Skip to content

Instantly share code, notes, and snippets.

@worace
worace / miner.go
Created January 22, 2015 02:42
crude golang gitcoin miner for https://github.com/worace/git-coin
package main
import (
"bytes"
"crypto/sha1"
"encoding/hex"
"fmt"
"io/ioutil"
"math/rand"
"net/http"
@worace
worace / gist:7867faa4a3f2d3ba33b1
Created January 24, 2015 19:35
sudoku huzzah
attempting to solve puzzle sample_puzzles/puzzle_38.txt
solved puzzle sample_puzzles/puzzle_38.txt in 0.078505 seconds
attempting to solve puzzle sample_puzzles/puzzle_44.txt
solved puzzle sample_puzzles/puzzle_44.txt in 21.837613 seconds
attempting to solve puzzle sample_puzzles/puzzle_43.txt
solved puzzle sample_puzzles/puzzle_43.txt in 2.452277 seconds
attempting to solve puzzle sample_puzzles/puzzle_3.txt
solved puzzle sample_puzzles/puzzle_3.txt in 0.376745 seconds
attempting to solve puzzle sample_puzzles/puzzle_33.txt
solved puzzle sample_puzzles/puzzle_33.txt in 0.341731 seconds

#Who uses Turing Slack? Turing has a fairly large community of people who use Slack: mentors, teachers, guests, students, and past students. Members should be mindful of other people's involvement in the Turing Slack community. Many mentors and guests are in different time zones, and most students need their sleep when they can get it (see: night owls or early birds). Please be aware of your local time and other users' local time when you are sending a message that will notify other members of the message. Most users have phone and/or email notifications (@channel (see below) and direct message) turned on.

#When Should I @Channel? Almost never. Especially in the community channel. Here are things to ask yourself before you send out a message using @channel:

  • Is this message important to everyone in this channel?
  • Does this message directly impact everyone in this channel?
  • Will this message wa
@worace
worace / benchmark.rb
Created February 9, 2015 22:52
Benchmark Examples in Ruby
require "benchmark"
# Benchmark perf of array.find
array = (1..1_000_000).to_a
res = Benchmark.measure do
array.find { |i| i == (array.length - 3) }
end
@worace
worace / code_review.md
Last active August 29, 2015 14:15
Turing Code Review Guidelines

Purpose of Code Review

Remember that the purpose of code review is to learn from the feedback of your peers and give constructive feedback to help one another improve. Even when it's not your code being reviewed, you can often pick up a lot of ideas from the discussion. When it is your code being reviewed, keep in mind that software is neither done nor perfect -- there's always something we can do better.

Code Review Process

  1. Clone the project -- project owner should make sure beforehand the project is pushed to github
  2. Setup dependencies (bundle, create DBs, etc.) -- A good project README will have clear instructions for what steps are necessary.
  3. Use the project (5 minutes) -- If it's a CLI try working through the commands a few times. If it's a web app, click around and try to follow a few different "user paths" through the app. Run the project. The project owner will probably need to serve as a guide here, but the goal is to quickly get a broad understanding of what the ap
@worace
worace / grandma.rb
Created February 12, 2015 19:03
Deaf Grandma Class-based refactoring
class Grandma
# returns true if the string
# is all caps
# otherwise returns false
def shouted?(string)
string == string.upcase
end
# returns true if you say "GOODBYE"
# otherwise returns false
@worace
worace / queries.rb
Last active August 29, 2015 14:15
user having ordered most items AR query
User.joins(:orders).
joins("INNER JOIN order_items ON order_items.order_id = orders.id"). #order_item is not an assn of user, so we need to manually specify the join path
group(:user_id). # group by user_id so our eventual output will be user ids
order("count_order_items_item_id desc"). #name of this column is based on rails convention for naming count columns
count("order_items.item_id"). #count("order_items.item_id") -> alias col "count_order_items_item_id"
first(4)
#=> [[40, 80], [9, 50], [22, 50], [48, 50]]
# (array of [user_id, ordered_item_count])
@worace
worace / hi
Created February 19, 2015 21:53
markdown sample
# hello
## hello
@worace
worace / rotations.rb
Created February 24, 2015 22:51
rotations
def rotated?(word, original)
if word == original
true
else
(0..word.chars.length).map do |i|
word = (word.chars[1..-1] + [word.chars[0]]).join
return true if word == original
end
false
end
@worace
worace / gist:561fba1b5eef00652b11
Created March 31, 2015 23:34
Turing Struct Warmup

Warmup - The Turing Struct

Let's create a new Turing Struct class which wraps a hash and exposes its keys as methods.

A Turing Struct accepts a hash when it's initialized, e.g.:

TuringStruct.new({my: "hash"})