Skip to content

Instantly share code, notes, and snippets.

View owainlewis's full-sized avatar

Owain Lewis owainlewis

View GitHub Profile
@owainlewis
owainlewis / Rails3.markdown
Created April 29, 2012 16:54
Rails 3 with Mongoid and Rspec

Generating the app

rails new example_app --skip-activerecord \
                        --skip-testunit

Gems

@owainlewis
owainlewis / deployer.rake
Created May 8, 2012 10:18 — forked from morgoth/deployer.rake
Rake task to copy local files to remote server via FTP
# Rake task to copy local files to remote server via FTP
# required credentials.yml file, that contains keys:
# server, username, password
require "net/ftp"
require "yaml"
class FTPClient
attr_reader :remote_path
@owainlewis
owainlewis / cassandra.markdown
Created May 8, 2012 19:35
Cassandra Quick Start

Start Cassandra

sudo bin/cassandra -f

Connect to the CLI

bin/cassandra-cli -h 127.0.0.1 -p 9160

@owainlewis
owainlewis / bottle_example.py
Created June 22, 2012 20:23
bottle.py example app
import os
from bottle import route, run, debug, template, request, validate, static_file, error
@route('/')
@route('/index.html')
def index():
return 'Index'
@route('/static/:filename')
def serve_static(filename):
@owainlewis
owainlewis / firefox-fix.js
Created June 23, 2012 17:57
Firefox background image rendering bug, jQuery
/*
* I encountered a strange bug with Firefox and dynamic background image updates.
* Background images can't be dynamically updated either through the console or via JavaScript.
* A simple hack is to update the opacity by a very small increment.
* This will force Firefox to re-render the background image correctly.
*/
var rand_opacity = ((0.9 + Math.floor((Math.random()*10)+1))/100);
$(el).css({"background-image":new_image, 'opacity':0.9 + rand_opacity});
@owainlewis
owainlewis / http.scala
Created June 28, 2012 15:18
Scala Apache HTTP
import org.apache.http.client._
import org.apache.http.client.methods._
import org.apache.http.impl.client._
class HTTP {
def getRequest: String = {
val client = new DefaultHttpClient()
val httpGet = new HttpGet("http://www.google.com")
val result = try {
@owainlewis
owainlewis / sort.rb
Created July 2, 2012 10:04
Column sorting
# Sort columns by param
#
# eg ?sort=id_reverse or ?sort=first_name
#
sort_by_params = lambda do
sort = params[:sort]
return 'id' if sort.blank? # sort by id if no params given
if sort.match(/_reverse/)
sort.split(/_reverse/).first + " DESC"
else
@owainlewis
owainlewis / model_to_csv.rb
Created July 2, 2012 17:58
Export Rails model to CSV
# Export Active Record model as a CSV file
#
def self.render_csv active_record_model
CSV.generate do |csv|
csv << active_record_model.column_names
active_record_model.all.each do |m|
values = active_record_model.column_names.map{ |f| m.send f.to_sym }
csv << values
end
end
@owainlewis
owainlewis / Cassandra CLI.md
Created July 13, 2012 12:18
Cassandra CLI

Basics

Create a keyspace

create keyspace store with replication_factor=1 and placement_strategy='org.apache.cassandra.locator.SimpleStrategy';

List keyspaces

show keyspaces;
@owainlewis
owainlewis / matplotinstall.sh
Created July 17, 2012 12:12
Machine Learning Packages for Python
sudo pip install -U scikit-learn
sudo pip install -f http://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.0/matplotlib-1.0.0.tar.gz matplotlib