Skip to content

Instantly share code, notes, and snippets.

var xpathObj = document.evaluate("//a[text()='Birmingham Mountain Radio']/@href/ancestor::h5[1]/following-sibling::div[contains(@class, 'userContent')]", document, null, XPathResult.ANY_TYPE, null)
var result = xpathObj.iterateNext();
while (result) {
if (result.textContent.indexOf('ticket')>=0 && (result.textContent.indexOf('win')>=0 || result.textContent.indexOf('free')>=0)) {
console.log('get dem tickets!');
}
result = xpathObj.iterateNext();
}
import java.awt.Color;
import java.util.*;
public class ColorUtilities {
public static Color getClosestColorFrom(List<Color> colorList, Color closestTo) {
double shortestDistance = Double.MAX_VALUE;
Color closestColor = closestTo;
for (Color color : colorList) {
if (!color.equals(closestTo)) {
double distance = (closestTo.getRed()-color.getRed())*(closestTo.getRed()-color.getRed())+
@bholzer
bholzer / a.js
Last active August 29, 2015 13:57
//Set up modules
(function() {
'use strict';
angular.module('autoMailer', ['ui.router']);
angular.module('autoMailer.providers', []);
angular.module('autoMailer.directives', []);
angular.module('autoMailer.filters', []);
angular.module('autoMailer.controllers', []);
})();
def import_contacts(file)
contacts = CSV.parse(Roo::Excelx.new(file.path))
Rails.logger.info(contacts)
end
def import_contacts(file)
contact_file = Tempfile.new(['contact','.xlsx'], :encoding => 'ASCII-8BIT')
contact_file.write(file.tempfile.read)
contacts = CSV.parse(Roo::Excelx.new(contact_file.path).to_csv)
end
<!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>
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
$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
});
});
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))
def printGrid(gridList):
for row in gridList:
print (row)