Skip to content

Instantly share code, notes, and snippets.

import groovy.transform.*
import groovyx.gpars.actor.*
import groovyx.gpars.group.*
@Immutable class Calculate {}
@Immutable class Work { int start, nrOfElements }
@Immutable class Result { double value }
@Immutable class PiApproximation { double pi ; long duration }
double calculatePiFor( int start, int nrOfElements ) {
@crazy4groovy
crazy4groovy / localfileserver.js
Last active August 29, 2015 14:02
Simple NodeJS file (stream) proxy for local system files
var http = require('http'),
fs = require('fs'),
port = process.argv[2] || '5000';
var m_names =
["January", "February", "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December"];
@crazy4groovy
crazy4groovy / simpleNodeNameCounter.groovy
Last active August 29, 2015 14:03
Generate a list of nodes in XML, and their frequency.
File f = new File(/C:\data.xml/)
int ratio = 10
String delim = '/'
def root = new XmlSlurper()
root.setFeature('http://apache.org/xml/features/disallow-doctype-decl', false) // allow XML doctype tag to exist
root = root.parse(f)
String rootName = root.name()
Map nodeCount = [:].withDefault{0}
@crazy4groovy
crazy4groovy / XmlNodeDataExtractor.groovy
Last active August 29, 2015 14:10
Extracts XML data into CSV format. Can especially help interpret large BISAC XML files.
/**
* @name nodeDataExtractor.groovy
* @author Steven Olsen <spam2steve@gmail.com>
* @description Extracts XML data into CSV format. Can especially help interpret large BISAC XML files.
* https://www.bisg.org/complete-bisac-subject-headings-2014-edition
* @version 0.1
*/
/////////////////////////////
File f = new File(args.size() >= 1 ? args[0] : /C:\input.xml/)
@crazy4groovy
crazy4groovy / flickr.groovy
Last active August 29, 2015 14:15
List top Flickr "Explore" images for the day
import groovy.json.*
String r = new URL("https://www.flickr.com/explore?data=1&day=${Calendar.instance.previous().format('YYYY-MM-dd')}&view=ju&start=1&count=500&append=0").text
int line = 0
String data
r.eachLine {
line++
if (it.contains('modelExport:')) {
data = it[15..-2]
println "******************* $line + ${data[0..200]}..."
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>sorting lists</title>
<script src="jquery-1.7.2.min.js"></script>
<script src="jquery.sortChildren.js"></script>
<script>
* {
font-size: 12pt;
font-family: monospace;
font-weight: normal;
font-style: normal;
text-decoration: none;
color: black;
cursor: default;
}
@crazy4groovy
crazy4groovy / java7install.sh
Last active August 29, 2015 14:20 — forked from mikakoivisto/java7install.sh
Install java 7 (or 8) silently on Ubuntu
cat - <<-EOF >> /etc/apt/sources.list.d/webupd8team-java.list
# webupd8team repository list
deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main
# deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main
EOF
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xEEA14886
echo debconf shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | /usr/bin/debconf-set-selections
@crazy4groovy
crazy4groovy / passthru.js
Created May 9, 2015 21:23
A simple NodeJS service that returns whatever URI resource comes after its own domain name (ala proxy).
var http = require('http'),
request = require('request');
http.createServer(function (req, resp) {
while (req.url.indexOf('/') === 0)
req.url = req.url.substring(1);
var opts = {url: decodeURIComponent(req.url), timeout: 3000}
try {
request(opts)
@crazy4groovy
crazy4groovy / webDriverIo.js
Last active August 29, 2015 14:20
Screenscraper snipet for Selenium (NodeJS)
//curl -O http://selenium-release.storage.googleapis.com/2.45/selenium-server-standalone-2.45.0.jar
//java -jar selenium-server-standalone-2.45.0.jar
//npm install webdriverio
var webdriverio = require('webdriverio');
var options = {
desiredCapabilities: {
browserName: 'firefox'
}