Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
nolanlawson / update_couchdb_views.pl
Created May 2, 2012
Simple perl script to query all design docs in a CouchDB database. Useful as a cron job to force permanent views to reindex automatically.
View update_couchdb_views.pl
#!/usr/bin/perl
# simple script to run a query on all the CouchDB saved views under the "projections" design
# document, in order to force CouchDB to re-index them.
#
# Usage:
#
# update_couchdb_views.pl couchdb_host couchdb_database
#
# e.g.
# update_couchdb_views.pl http://localhost:5984 honbot
@nolanlawson
nolanlawson / compare_solr_boosts.py
Created Jun 1, 2012
Script for comparing the different ways of "boosting" queries in Solr
View compare_solr_boosts.py
#!/bin/sh/env python
#
# Simple script for comparing the various ways of "boosting" queries in Solr,
# combined with the three main query parsers (lucene, dismax, and edismax).
# The idea is to generate md5sums of the search results, so I can quickly
# figure out which boost methods work the same as the other ones.
#
import re, urllib2, urllib, md5, json
@nolanlawson
nolanlawson / MultithreadedQuerySenderListener.java
Created Jun 6, 2012
Slight hack of the QuerySenderListener that fixes a bug in Solr 3.5.0 where spellcheck components that use collation/onlyMorePopular with query components get stuck on Thread.wait(). Plus, it's faster.
View MultithreadedQuerySenderListener.java
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@nolanlawson
nolanlawson / QuietSpellCheckComponent.java
Last active Oct 5, 2015
Slight tweak of the Solr SpellCheckComponent to make its output quieter when you only care about the collations
View QuietSpellCheckComponent.java
package org.healthonnet.solr;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.TokenStream;
@nolanlawson
nolanlawson / organize_android_strings_files.py
Created Sep 18, 2012
Python script to help with outputting Android strings.xml files in an organized format.
View organize_android_strings_files.py
#!/bin/sh/env python
# organize the strings.xml files used for Android projects
# assumes I have some strings in the English one that don't need to be translated, so these
# are separated from the rest. Also assumes I always keep up with the French translations.
#
# usage: just run it from the res/ folder
#
import sys, re, os
from xml.dom.minidom import parseString
@nolanlawson
nolanlawson / generate_random_colors.py
Created Oct 1, 2012
generate some random colors for CatLog
View generate_random_colors.py
#!/bin/sh/env python
#
# Quick script to generate eye-pleasing colors based on a single Saturation and Value (Brightness).
# Print out in HTML hex format
#
# usage: generate_random_colors.py numColors saturation value multiMode htmlMode
#
import sys, colorsys, random
@nolanlawson
nolanlawson / BadSpellcheckRegexFilter.groovy
Created Jan 24, 2013
Gist for the best regex for escaping bad spellcheck suggestions in Groovy. Should be easily portable to JavaScript and Java, or just paste into groovysh.
View BadSpellcheckRegexFilter.groovy
import java.util.regex.Pattern;
// note that you won't need to escape the $ in Java
Pattern filterBadSpellcheckPattern = Pattern.compile("[:.,;!?\\)\\('\"\\-\u2026\u00AE\u00A9]\$")
@nolanlawson
nolanlawson / cordova-vs-browser.js
Last active Dec 12, 2015
Examples showing how to detect Cordova vs. browser, and how to debug Cordova.
View cordova-vs-browser.js
/**!
*
* Utility class for detecting whether or not we're in PhoneGap vs. the browser
* @author nolan
**/
/** set to true if you want to pretend we're PhoneGap in the browser **/
var FORCE_CORDOVA = false;
var CordovaVsBrowser = {
@nolanlawson
nolanlawson / fix_android_apk.py
Last active Dec 14, 2015
Fixes an Android APK built by PhoneGap Build to correct the problem of xhdpi images not being properly added (https://github.com/phonegap/build/issues/9). Requires apktool and jarsigner to already be installed.
View fix_android_apk.py
#!/usr/bin/env python
# fix an Android APK built by PhoneGap Build to correct the problem of
# xhdpi images not being correctly added (https://github.com/phonegap/build/issues/9)
#
# REQUIRES apktool and jarsigner to already be installed and on the PATH.
#
# usage: fix_android_apk.py www/config.xml InputFile.apk OutputFile.apk
#
import os,sys,shutil,tempfile,xml.dom.minidom
@nolanlawson
nolanlawson / minify_everything.sh
Last active Apr 7, 2020
Simple JS and CSS minification script
View minify_everything.sh
#!/bin/bash
#
# Minify every JS and CSS file in the given directories, except for anything with "min" in the name.
# Creates new files with the names *.min.js and *.min.css. Deletes the originals. Modified all the html files
# to say ".min.js" and ".min.css" instead of ".js" and ".css".
# Also has an optional debug mode that removes strict mode without minifying.
#
# usage: minify_everything.sh my/yuicompressor.jar my/js/folder my/css/folder debug_mode[0,1] [htmlFiles ...]
#