Skip to content

Instantly share code, notes, and snippets.

@jawspeak
jawspeak / upgrade server ree 1.8.7 to ruby 1.9.3.sh
Last active December 10, 2015 05:18 — forked from anonymous/upgrade server ree 1.8.7 to ruby 1.9.3.sh
upgrade server ree 1.8.7 to ruby 1.9.3. - install rvm with ruby 1.9.3 - install passenger for the new ruby - update passenger to use the new ruby - uninstall the old ruby
# prereqs
sudo apt-get update
sudo /usr/bin/apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config
# multiuser rvm
$ \curl -L https://get.rvm.io | sudo bash -s stable --ruby=ruby-1.9.3-p362
# add user to rvm group
sudo usermod -a -G rvm ubuntu
$ logout and log back in
@jawspeak
jawspeak / mysql_db_and_table_size_queries.sql
Created September 27, 2012 00:41 — forked from chrisk/mysql_db_and_table_size_queries.sql
MySQL queries to show the size of databases and tables reported by information_schema
-- Check the total size of each database
SELECT
tables.TABLE_SCHEMA AS database_name,
ROUND(SUM(tables.DATA_LENGTH + tables.INDEX_LENGTH) / POWER(2, 30), 3) AS database_size_in_gb
FROM information_schema.TABLES AS tables
GROUP BY tables.TABLE_SCHEMA
ORDER BY database_size_in_gb DESC;
-- List all tables larger than 1 GB
SELECT
@jawspeak
jawspeak / c10k-test-client.c
Created December 19, 2011 16:32 — forked from rsms/c10k-test-client.c
C binary to drive heavy load on a web server. 10K+ requests / second. Seems roughly equivalent to 'ab', and heaver load than httperf.
// HTTP client for testing high connection concurrency
// Authors: Richard Jones and Rasmus Andersson
// Released in the public domain. No restrictions, no support.
// SEE:
// http://rsms.me/2009/10/05/10k-comet-connections.html
#include <sys/types.h>
#include <sys/time.h>
#include <sys/queue.h>
@jawspeak
jawspeak / realtime_address_correction.rb
Created December 6, 2011 00:12
Peachtree Data's new realtime address validation service example. Ruby with handsoap gem. 2011-12-05. Their service is described here http://www.linkedin.com/company/peachtree-data-inc./fast-address-real-time-address-validation-368341/product
require 'handsoap'
require 'openssl'
class AddressValidator < Handsoap::Service
self.logger=$stdout
# https://fastaddress-beta.peachtreedata.com/rtac/?wsdl
ENDPOINT = {:uri => 'https://fastaddress-beta.peachtreedata.com/rtac/', :version => 1}
endpoint ENDPOINT
@jawspeak
jawspeak / asset_optimizer_after.rb
Created September 27, 2011 15:45
Before and after refactoring of an asset checker - that looks at all assets in a rails project, and finds the ones that appear to be unreferenced.
require 'rubygems'
require 'find'
require 'pp'
class UnusedImagesFinder
def find_unused_assets
puts "Lists unused files based upon explicit programatic checks. Requires manual confirmation before deletion."
puts "------------------ Building css from sass ------------------"
system 'rake build_static:stylesheets'
@jawspeak
jawspeak / BeanDumper.java
Created August 19, 2010 16:53
BeanDumper useful for printing java objects
package com.example.utility;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import static com.google.common.collect.Iterables.*;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
import org.joda.time.LocalTime;
import java.beans.BeanInfo;
@jawspeak
jawspeak / FactoryRequestScope.java
Created July 15, 2010 22:58
New request scope for factory beans. Be careful though since it does not support injecting FactoryBeans as collaborators, but we didn't want this so it's okay. Solves the problem of Spring's Stupid FactoryBeans being instantiated multiple times per req
package com.example.spring;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.web.context.request.AbstractRequestAttributesScope;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
public class FactoryRequestScope extends AbstractRequestAttributesScope{
@jawspeak
jawspeak / Example Use Google Collections.java
Created July 1, 2010 01:52
java google collections functional programming style
// Use functional programming idioms that google collections (now called google guava) give you.
// Given:
private static final Set<String> CLEARABLE_PATHS = Sets.newHashSet("/app/search", "/app/logout");
// Don't be iterative:
// BAD
private boolean shouldClearCookie() {
for (Iterator<String> stringIterator = CLEARABLE_PATHS.iterator(); stringIterator.hasNext();) {
String clearablePath = stringIterator.next();
@jawspeak
jawspeak / CachingByTypeBeanFactory.java
Created June 26, 2010 02:02
spring CachingByTypeBeanFactory to cache lookups by type
package com.example.spring;
import org.apache.log4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@jawspeak
jawspeak / make.sh
Created May 14, 2010 16:57
make.sh maven wrapper
#!/usr/bin/env bash
# make.sh script to build maven
path=$(cd ${0%/*} && pwd -P)
. $path/mvnopts
# contents of mvnopts:
# export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=512m"
usage()
{