Skip to content

Instantly share code, notes, and snippets.

package org.harbor;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@sam
sam / HarborServlet.java
Created August 28, 2012 19:54
Servlet Example
public class HarborServlet extends HttpServlet {
private ScriptingContainer container;
private HttpServlet servlet;
@Override
public void init() {
String classpath = getServletContext().getRealPath("/WEB-INF/classes");
List<String> loadPaths = Arrays.asList(classpath.split(File.pathSeparator));
container = new ScriptingContainer();
@sam
sam / jar-bootstrap.rb
Created August 10, 2012 21:27
Map Benchmarks under JRuby 1.7.0.preview2
require "java"
hash_map = {}
java_import com.hazelcast.core.Hazelcast
at_exit { Hazelcast.shutdown_all }
hazel_map = Hazelcast.get_map "benchmark"
java_import org.infinispan.Cache
java_import org.infinispan.manager.DefaultCacheManager
@sam
sam / topsongs.rb
Created August 7, 2012 18:30
JRuby + Xerces
# You can download the Xerces jar here:
# http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22xerces%22
require "java"
require "xerces-2.4.0-sources.jar"
url = java.net.URL.new("http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/limit=10/xml")
connection = url.open_connection
builder = javax.xml.parsers.DocumentBuilderFactory.new_instance.new_document_builder
@sam
sam / copy-photos.sh
Created June 13, 2012 21:16
Quick and dirty script to copy a list of files from site A to site B
A="example1"
B="example2"
SUM="0"
while read line; do
if [ -f "/nfs/$B/private/$line" ]; then
echo "PATH: $line already exists"
else
line_d="$(dirname "/nfs/$B/private/$line")"
if [ -d $line_d ]; then
@sam
sam / gist:2778268
Created May 23, 2012 22:38
Install OpenJDK7 on OSX
if ! [ -d /Library/Java/JavaVirtualMachines/1.7.0u6.jdk ]; then
echo "Downloading OpenJDK 7"
curl -o /tmp/OpenJDK-7.dmg http://openjdk-osx-build.googlecode.com/files/OpenJDK-OSX-1.7-universal-u-jdk-jdk7u6-b10-20120522.dmg
echo "Attaching DMG image"
hdiutil attach /tmp/OpenJDK-7.dmg
echo "Copying JDK into available Java Virtual Machines"
sudo cp -R /Volumes/OpenJDK\ 7\ \(Mac\ OS:X\ Port\)/1.7.0u.jdk /Library/Java/JavaVirtualMachines/1.7.0u6.jdk
echo "Detach DMG image"
hdiutil detach /Volumes/OpenJDK\ 7\ \(Mac\ OS:X\ Port\)
@sam
sam / 0_template.html
Created May 8, 2012 15:21
Components
<td>
<FormattedDate
id="search_item_expiration_date[]"
format="admin-long"
value=#rsrs.created_at />
</td>
@sam
sam / gist:2629092
Created May 7, 2012 17:23
Remove bad photos from database
psql -h db.example -c <<"EOS" example_client_database
CREATE OR REPLACE FUNCTION delete_photo(uuid) RETURNS INTEGER AS $$
DECLARE
updated_photos_count INTEGER;
updated_photo_translations_count INTEGER;
updated_channels_photos_count INTEGER;
BEGIN
DELETE FROM photos WHERE uuid = $1;
GET DIAGNOSTICS updated_photos_count = ROW_COUNT;
@sam
sam / ftp-example.rb
Created May 3, 2012 19:37
Example for org.apache.ftpserver on JRuby
require "java"
jars = File.join(File.dirname(__FILE__), "*.jar")
Dir[jars].each { |jar| require jar }
import org.apache.ftpserver.FtpServer
import org.apache.ftpserver.FtpServerFactory
import org.apache.ftpserver.listener.ListenerFactory
server_factory = FtpServerFactory.new
@sam
sam / dbcompare
Created April 2, 2012 19:37
dbcompare
#!/usr/bin/env bash
SOURCE=
TARGET=
DATABASE=
TABLE=
function usage() {
cat <<"EOS"
USAGE: dbcompare -h source target database [ table ]