Skip to content

Instantly share code, notes, and snippets.

def printGrid(gridList):
for row in gridList:
print (row)
def checkRows(g):
for rows in g:
numbersInRow = [] #List to keep track of numbers that appear in the row
for number in row:
if number != 0 and number in numbersInRow:
return g.index(row) #The number has already appeared in the row, so return the row that fails
else:
numbersInRow.append(number) #This number hasnt appeared in the row yet, so add it to the list
print(numbersInRow)
return True #Nothing failed, so the row check succeeded
def escape_response
escape = lambda do |unescaped_response|
unescaped_response.each do |value|
if value.is_a?(String)
value = ERB::Util.h(value)
elsif [Array, Hash].any?{|klass| value.is_a?(klass) }
value = escape.call(value)
end
end
end
class ApplicationController < ActionController::Base
after_filter :escape_response
def escape_response
if response.content_type == 'application/json'
response.body = escape_hash_or_array(JSON.parse(response.body)).to_json
end
end
#realized that this also creates a new Proc object for every recursive call. Needs to be fixed
<html>
<head>
</head>
<body>
<canvas id="drawing-board" height="1000" width="1000"></canvas>
<script type="text/javascript">
var c = document.getElementById("drawing-board");
var ctx = c.getContext("2d");
window.addEventListener('resize', resizeCanvas, false);
require 'koala'
graph = Koala::Facebook::API.new("redacted")
two_weeks_ago = Time.now - (2*7*24*60*60)
members = graph.get_object("355625917946909/members")
member_names = members.map{|mem| mem["name"]}
feed = graph.get_object("355625917946909/feed?fields=from,likes,link,comments.limit(10000000)&limit=10000000&since=#{two_weeks_ago.to_i}")
most_liked = feed.select{|post| !post["likes"].nil? }.sort {|a,b| b["likes"]["data"].size <=> a["likes"]["data"].size}
posters_in_last_two_weeks = feed.map {|post| post["from"]["name"] }.uniq
commenters_in_last_two_weeks = feed.select{|post| !post["comments"].nil?}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
var Vector = function(x, y) {
this.x = x;
this.y = y;
this.addInPlace = function(vector) {
this.x += vector.x;
this.y += vector.y;
return this;
}
require 'koala'
graph = Koala::Facebook::API.new("APIKEY")
one_year_ago = Time.now - (52*7*24*60*60)
feed = graph.get_object("355625917946909/feed?fields=from,likes.limit(10000000),link,comments.limit(10000000)&limit=10000000&since=#{one_year_ago.to_i}")
most_liked = feed.select{|post| !post["likes"].nil? }.sort {|a,b| b["likes"]["data"].size <=> a["likes"]["data"].size}
most_liked[0..15].each do |post|
puts '%-40s' % "#{post["from"]["name"]}:" + "www.facebook.com/groups/#{post["id"].gsub(/_/,"/")} " + "Likes: #{post["likes"]["data"].length}"
end
// An attempt at implementing the polygon labeling algo at:
// http://mapcontext.com/autocarto/proceedings/auto-carto-8/pdf/an-algorithm-for-locating-candidate-labeling-boxes-within-a-polygon.pdf
// I'm so sorry if you ever have to try and fix this code. Godspeed
function findOptimalLabelLocation(section_point_array, name) {
var xy_objs = _.map(section_point_array, function(xy) { return {x: xy[0], y: xy[1]} });
var simplified = simplify(xy_objs, 1);
var edges = [];
for (var i = 0; i < simplified.length-1; i++) {
var current_point = simplified[i];
var next_point = (i == simplified.length-1) ? simplified[0] : simplified[i+1];