This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Matasano { | |
def hexToBytes(hex: String): Array[Byte] = { | |
hex.replaceAll("[^0-9A-Fa-f]", "").sliding(2,2).toArray.map(Integer.parseInt(_, 16).toByte) | |
} | |
def bytesToHex(bytes: Array[Byte]): String = { | |
bytes.map("%02x" format _).mkString | |
} | |
def encode64(b: Array[Byte]): String = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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', []); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def import_contacts(file) | |
contacts = CSV.parse(Roo::Excelx.new(file.path)) | |
Rails.logger.info(contacts) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
OlderNewer