Skip to content

Instantly share code, notes, and snippets.

@CitizenOfRome
CitizenOfRome / cables.py
Created January 12, 2012 05:19
My code from CodeSprint2
import itertools
C = int(raw_input())
for c in xrange(C):
N = int(raw_input())
cities = [int(x) for x in raw_input().split()]
cables = [int(x) for x in raw_input().split()]
# dist = sum([sum([(cables[i]-cables[j])*(cities[i]-cities[j]) if cables[i]>cables[j] else (cables[j]-cables[i])*(cities[i]-cities[j]) for i in xrange(j,N)]) for j in xrange(N)])
# pairs = []
# sums = 0
# for i in xrange(N-1):
@CitizenOfRome
CitizenOfRome / html_abs.js
Created January 12, 2012 05:33
QuickTestJS a quick way to check-out Javascript snippets
if(!document.getElementById("viewer")) document.body.innerHTML+="<div id='viewer'></div>";
viewer = document.getElementById("viewer");
include = function(st) {
ext = st.split('.').pop();
ext = ext.toLowerCase();
switch(ext){
case "js":
viewer.innerHTML+='<script type="text/JavaScript" src="'+st+'"></script>';
break;
case "css":
@CitizenOfRome
CitizenOfRome / collatz.py
Created January 12, 2012 09:40
Some stuff I did for fun :)
#http://xkcd.com/710/ or you could leave the job to your computer and go out with your friends :P
number = int(raw_input())
stack = []
while number!=1:
if number%2==0: number = number//2
else: number = 3*number+1
stack.append(number)
print(len(stack))
@CitizenOfRome
CitizenOfRome / get_data.php
Created February 10, 2012 05:09
CollegeFinder
<?php
include_once('simple_html_dom.php');
$target_url = $_REQUEST["url"];
$html = new simple_html_dom();
$html->load_file($target_url);
foreach($html->find('td[class=pbe]') as $img) {
echo $img->src."<br />";
echo $img."<br/>";
}
?>
@CitizenOfRome
CitizenOfRome / index.html
Created May 22, 2012 08:47
Purely Client-Side Interactive Image Vamp-Up http://bit.ly/ba2nGV
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en">
<head>
<title>Interactive Image Vamp up with jQuery, CSS3 and PHP</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description"
content="Interactive Image Vamp up with jQuery, CSS3 and PHP" />
<meta name="keywords" content="jquery, php, fancy, css3, rotation" />
<link type="text/css" href="css/jquery.ui.theme.css" rel="stylesheet" />
<link type="text/css" href="css/jquery.ui.core.css" rel="stylesheet" />
@CitizenOfRome
CitizenOfRome / UFCOE.parseUri.js
Last active April 7, 2017 09:09 — forked from mrclay/UFCOE.parseUri.js
Parse a URI using the browser's DOM
(function (w, d) {
//https://gist.github.com/1847816
var a, k = 'protocol hostname host pathname port search hash href'.split(' ');
w.UFCOE = w.UFCOE || {};
/**
* Parse a URI, returning an object similar to Location
*
* Usage: UFCOE.parseUri("hello?search#hash").search -> "?search"
*
* @param String url
nextNode = function(node) {
if(node===document) {
console.log("Document");
node = null;
}
else if(node.firstChild) {
console.log("FirstCHild");
node = node.firstChild;
}
else if (node.nextSibling) {
@CitizenOfRome
CitizenOfRome / Approve_FB_Group_join_requests.js
Last active December 17, 2015 04:09
Approve all pending Facebook Groups join requests - Must be run from the "view all" page
// Select all Approve buttons
a=document.querySelectorAll("a.uiButton.uiButtonConfirm");
// Fire the click event on each of them
for(var i=0,j=a.length;i<j;i++){fireEvent(a[i], "click")}
// Card Constructor
var Card = function(suit,cardNumber){
var prototype=this;
prototype.getNumber=function(){return cardNumber;};
prototype.getSuit=function(){return suit;};
prototype.getSuitName=function(){
switch(suit){
case 1: return "Hearts";
case 2: return "Spades";
case 3: return "Diamonds";
#!/bin/python
# Head ends here
import math
def getArrayIndex(stringIndex, size):
stringIndex += 1 # Switch base to 1 from 0
row = math.ceil(float(stringIndex)/size)
col = stringIndex - (row-1)*size
return row, col
def displayPathtoPrincess(n,grid):
#print all the moves here