Skip to content

Instantly share code, notes, and snippets.

@tomgullo
tomgullo / test_rsorl_ext.rb
Created April 19, 2012 14:27
Sample client using rsolr ext
require 'rubygems'
require 'rsolr'
require 'rsolr-ext'
solr = RSolr::Ext.connect :url => 'http://localhost:8983/solr'
#add
docs = [
{:id => 1, :words_txt => 'blue green red', :type_s => 'book'},
{:id => 2, :words_txt => 'war of worlds blue', :type_s => 'book'},
@tomgullo
tomgullo / query_solr_with_dates.sh
Created April 6, 2012 13:04
query solr with dates using curl
#!/bin/sh
# get documents older than 90 days
curl 'http://localhost:8983/solr/select?q=date_tdt:%5B*%20TO%20NOW-90DAYS%5D'
@tomgullo
tomgullo / apache-404.conf
Created April 3, 2012 01:18
Ban 404 from script kiddies
[Definition]
failregex = <HOST> - - \[.*\] \"(GET|POST).*(phpMyAdmin|phpmyadmin|dbadmin|mysql|myadmin|w00t|mysqladmin).* 404
ignoreregex =
@tomgullo
tomgullo / apache-filter-these.conf
Created April 3, 2012 01:12
fail2ban conf file for Apache
failregex = ^<HOST> -.*/(phpMyAdmin|phpmyadmin).*$
^<HOST> -.*CONNECT.*$
@tomgullo
tomgullo / underscore_template.html
Created March 26, 2012 15:12
underscore template example
<html>
<head>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="underscore-min.js"></script>
<script>
$(document).ready(function() {
var people_records = {people:[{first_name:'joe', last_name:'shmo'}, {first_name:'jane', last_name:'smith'}]};
var row_template = "<% _.each(people, function(obj) { %> <tr> <td> <%= obj.first_name %> </td> <td> <%= obj.last_name %> </td> </tr> <% }); %>";
$("#table_rows").html( _.template( row_template, people_records ) );
@tomgullo
tomgullo / example_using_qunit.html
Created March 20, 2012 18:49
Example testing js using qunit
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>QUnit Tests</title>
<link rel="stylesheet" href="qunit.css">
</head>
<body>
<h1 id="qunit-header">QUnit Hello World</h1>
<h2 id="qunit-banner"></h2>
@tomgullo
tomgullo / passing_args_and_callbacks.js
Created March 16, 2012 14:24
Simple example of callbacks
var App = {
something: function(args1, callback) {
console.log("in something 2");
callback.apply(App, arguments);
return false;
},
dothis: function() {
var l = ['one','two'];
var s = "hi";
App.something(s, function(args1) {
@tomgullo
tomgullo / convert_roman_to_dec.groovy
Created March 5, 2012 14:08
Groovy script to convert decimals to roman numerals
/*
The key is to map unique roman numerals to binary values, then start from traversing through the list from high values to low values.
When binary is greater, start building the roman string, subtracting from the binary as you go.
Takeaway: If writing a conversion problem, make list mapping one to another. Also, look for "shortcuts" or patterns to avoid full lists mapping each value.
*/
def binaryToRoman(int binary) {
def RCODE = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"]
@tomgullo
tomgullo / load.rb
Created February 19, 2012 16:24
load zips into mongodb using ruby
require 'rubygems'
require 'mongo'
@conn = Mongo::Connection.new
@db = @conn['geo-db']
@coll = @db['places']
File.open("US.txt", "r").each do | line |
sp = line.split("\t")
#country zip state region lat long
@tomgullo
tomgullo / load_mongodb.js
Created February 15, 2012 15:45
Load MongoDB with test data
function randomOne(from, to) {
return Math.floor(Math.random() * (to - from + 1) + from);
}
var name = ['tom', 'jeff', 'carol', 'mike', 'robert', 'suzan', 'wendy']
var st = ['va', 'md', 'ny', 'ca', 'fl', 'oh', 'mi'];
var food = ['pizza', 'hamburger', 'spaghetti', 'burrito', 'seafood', 'indian', 'thai']
var quote = ['abc abc abc abc....', 'cba cba cba cba....', 'xyz xyz xyz...',
'jio jio jio....', 'oww oww oww...', 'fow fow fow...', 'soi soi soi...']