Skip to content

Instantly share code, notes, and snippets.

500.times do
Post.create!(title: Faker::Company.catch_phrase,
body: Faker::Lorem.paragraphs(4)).tags << tags.sample(2)
end
$(document).ready(function () {
$('form').submit(function() {
event.preventDefault();
$.post("/rolls").done(function(results) {
var html = $(results).find('#die').html();
$('#die').html(html);
});
});
});
@andmcgregor
andmcgregor / gist:5856248
Last active December 20, 2017 15:42
Spinning wheel javascript
<html>
<canvas id="wheel" width="500" height="500">
<p>Upgrade your browser!</p>
</canvas>
<script type="text/javascript">
var images = ["http://bahaaaaal.com/wp-content/uploads/2013/01/siam-food-gallery.jpg","http://images.sciencedaily.com/2013/03/130307124701-large.jpg"] // sample images
function drawSlice(startAngle, i) {
export PS1='\[\033[01;33m\]\u@\h\[\033[01;31m\] \W$(__git_ps1 " (%s)") \$\[\033[00m\] '
class ToDoView
def initialize
list if ARGV.include? 'list'
add if ARGV.include? 'add'
delete if ARGV.include? 'delete'
end
def list
list = ARGV[1] ? TodoController::list({ list: ARGV[1] }) : TodoController::list
puts list.map {|task| (task.completed ? "\033[92m✔\033[0m " : "\033[91m✘\033[0m ") + task.name.to_s } # .join("\n")
DELETE FROM voters
WHERE homeowner = 1
AND employed = 1
AND children_count = 0
AND party_duration < 3
AND (SELECT voters.id
FROM voters
INNER JOIN votes
ON voters.id = votes.voter_id
INNER JOIN congress_members
# encoding: utf-8
@andmcgregor
andmcgregor / brute_force_sudoku.rb
Created June 10, 2013 05:24
Brute force sudoku (work in progress). Need to: - make the code ALOT more efficient. I have a few ideas how to do this. - improve found algorithm to actually check that the board is solved (rather than just adding up the numbers and seeing if they equal 405). - pause the search once a solution is found.
class SudokuCell
attr_accessor :index, :value, :row, :column, :box
def initialize(initial_value, index)
@value = initial_value != 0 ? initial_value : 0
@index = index.to_i
@row = (0..81).to_a[((index/9)*9..(index/9)*9+8)]
@column, at_index, incrementor = [], index, +9
until @column.count == 9 do
if at_index < 0
incrementor = +9
def green
"\033[92m" + yield + "\033[0m"
end
puts "\033[92m" + "Green = First letter" + "\033[0m"
puts "\033[91m" + "Red = Second letter" + "\033[0m"
puts "\033[93m" + "Yellow = Third letter" + "\033[0m"
puts "\033[94m" + "Blue = Fourth letter" + "\033[0m" if !trace[3].nil?
puts "\033[95m" + "Pink = Fifth letter" + "\033[0m" if !trace[4].nil?