Skip to content

Instantly share code, notes, and snippets.

Owain Lewis owainlewis

Block or report user

Report or block owainlewis

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@owainlewis
owainlewis / Rails3.markdown
Created Apr 29, 2012
Rails 3 with Mongoid and Rspec
View Rails3.markdown

Generating the app

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

Gems

@owainlewis
owainlewis / deployer.rake
Created May 8, 2012 — forked from morgoth/deployer.rake
Rake task to copy local files to remote server via FTP
View deployer.rake
# 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
View cassandra.markdown

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 Jun 22, 2012
bottle.py example app
View bottle_example.py
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 Jun 23, 2012
Firefox background image rendering bug, jQuery
View firefox-fix.js
/*
* 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 Jun 28, 2012
Scala Apache HTTP
View http.scala
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 {
View sort.rb
# 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 Jul 2, 2012
Export Rails model to CSV
View model_to_csv.rb
# 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
View Cassandra CLI.md

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 Jul 17, 2012
Machine Learning Packages for Python
View matplotinstall.sh
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
You can’t perform that action at this time.