Skip to content

Instantly share code, notes, and snippets.

@elvuel
elvuel / README.md
Created July 2, 2013 09:13 — forked from keikubo/README.md
Nginx + Unicorn for Rails

Nginx + Unicorn for Rails on Rackhub

Description:

This script enables you to launch your Rails application in production environment (port:80) with Nginx and Unicorn.

Installation:

Please make sure that your Gemfile in your rails application includes unicorn.

# create the template
template = PageOfflineTemplate.new
template.quote = quote
template.pages = quote.build_pages
# Here I render a template with layout to a string then a PDF
pdf = PDFKit.new template.render_to_string(:template=>"quotes/review.html.haml")
@elvuel
elvuel / cequel-cassandra-cql-memo.rb
Created May 16, 2013 01:57
cequel & cassandra-cql patch for Cassandra1.2 user Authentication
# /home/elvuel/.rvm/gems/ruby-2.0.0-p0@rails/gems/cequel-0.5.6/lib/cequel/keyspace.rb
def configure(configuration = {})
@configuration = configuration
@hosts = configuration[:host] || configuration[:hosts]
@thrift_options = configuration[:thrift].try(:symbolize_keys) || {}
@keyspace = configuration[:keyspace]
@username = configuration[:username] # ++
@password = configuration[:password] # ++
# reset the connections
~/projects/jruby ➔ cat my_java_thing.rb
require 'java'
java_package 'foo.bar'
class SomeJavaThing
java_signature 'void main(String[] args)'
def self.main(args)
puts args.to_a
end
#! /bin/ruby1.8.7 -Ku
require 'socket'
require 'open-uri'
require 'time'
require 'json'
require 'base64'
def cut str, len=100
a = str.scan /./u
#
# A basic, synthetic benchmark of the impact HTTP client has
# on the speed of talking to ElasticSearch in the Tire gem.
#
# In general, Curb seems to be more then two times faster the RestClient, in some cases it's three
# to five times faster. I wonder if keep-alive has anything to do with it, but it probably does.
#
# Run me with:
# $ git clone git://github.com/karmi/tire.git
# $ cd tire
# encoding: utf-8
# code from: http://techtime.getharvest.com/blog/harvest-is-now-on-ruby-1-dot-9-3
# and also: https://gist.github.com/1976864
# Serialized columns in AR don't support UTF-8 well, so set the encoding on those
class ActiveRecord::Base
def unserialize_attribute_with_utf8(attr_name)
traverse = lambda do |object, block|
if object.kind_of?(Hash)
@elvuel
elvuel / .jrubyrc
Last active December 14, 2015 15:09 — forked from tychobrailleur/.jrubyrc
# Example of .jrubyrc
# Set compilation mode. JIT = at runtime; FORCE = before execution. (JIT, FORCE, OFF, OFFIR)
# compile.mode = FORCE
# Dump to console all bytecode generated at runtime.
# compile.dump = true
# Enable verbose JIT logging (reports failed compilation)
# jit.logging.verbose = true
@elvuel
elvuel / massive_record_tire.rb
Created March 7, 2013 03:35
ruby hbase elasticserach with massive_record and tire
# encoding: utf-8
# investigation
require 'massive_record'
require 'active_model'
require 'json'
require 'tire'
require 'rest_client'
MassiveRecord::ORM::Base.connection_configuration = {
:host => 'localhost',
@elvuel
elvuel / Verify.txt
Last active December 13, 2015 19:49
Hadoop setup
hadoop fs -mkdir /invest
echo 'hello world' >> /tmp/invest1.txt
echo 'hello hadoop' >> /tmp/invest2.txt
hadoop fs -copyFromLocal /tmp/invest2.txt /invest
hadoop fs -ls /invest
cd /usr/local/hadoop//share/hadoop/mapreduce
hadoop jar hadoop-mapreduce-examples-2.0.3-alpha.jar wordcount /invest /invest-output
...