Skip to content

Instantly share code, notes, and snippets.

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?}
<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);
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
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
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 printGrid(gridList):
for row in gridList:
print (row)
import sys
def main():
Scanner = Scanner("info.dat")
Boolean = Scanner.readbool()
String = Scanner.readstring()
Number = Scanner.readint() #no need to wrap this in int() since readint will do that automatically
if Boolean: #Here, you don't need to do == "True" because the readbool function automatically converts things correctly
print('{s}\n"{s}"'.format(s=String))
$files.forEach(function ($file) {
console.log('Should request'); //This runs as many times as there are images
var filePromise = $http.post('/api/images/upload').then(function (aws){ //This request runs only once
console.log(aws) //This also runs as many times as there are images, but aws is same EVERY TIME.
//Go on to upload file to S3
});
});
filename = "2009_shots.csv"
def readfile(fname):
'''Read the input file, return a list with all lines from the file'''
f = open(fname, 'r')
file_lines = f.readlines()
f.close
for i in range(0, len(file_lines)):
file_lines[i] = file_lines[i].strip()
return file_lines
<!DOCTYPE html>
<html>
<body bgcolor="cyan">
<h1>My First Program</h1>
<button onclick="X()"><p ID="Y">Hey You!</p></button>
<input type="text" value="Z" name="Z">
<button onclick="Q()"><p>..</p></button>