Skip to content

Instantly share code, notes, and snippets.

View kares's full-sized avatar
💤

Karol Bucek kares

💤
View GitHub Profile
@wnuqui
wnuqui / gist:4653064
Last active December 11, 2015 20:09
3 bare bone rails applications using 3 jruby application servers (all running in heroku cedar)
# JAVA_OPTS and Procfiles
JAVA_OPTS: -Djruby.memory.max=384m -Xmx384m -Xms256m -Xss512k -XX:+UseCompressedOops -XX:+PrintGCDetails
# puma backed app's Procfile
web: bundle exec rails server puma -p $PORT -e $RACK_ENV
# torquebox-lite backed app's Procfile
web: bin/torquebox-lite -b 0.0.0.0 -p $PORT --max-threads=8
@madsheep
madsheep / kitten_mailer.rb
Created September 10, 2013 14:58
Any mailer inherited from this one will have random cat included as an attachment.
class KittenMailer < ActionMailer::Base
def mail *args
attachments['cat.jpeg'] = open("http://placekitten.com/#{rand(300)+300}/#{rand(300)+300}").read
super
end
end
@headius
headius / ffi_crypt.rb
Created September 19, 2013 16:17
Binding the libc 'crypt' function using FFI.
require 'ffi'
module Crypt
extend FFI::Library
ffi_lib 'c'
attach_function :crypt, [:string, :string], :string
end
p Crypt.crypt 'this is a string', 'this is the salt'
/*
* Sugar for type detection working across frames and browsers ;)
*
* Detected types
*
* 'arguments', 'array', 'boolean', 'date', 'document', 'element', 'error', 'fragment',
* 'function', 'nodelist', 'null', 'number', 'object', 'regexp', 'string', 'textnode',
* 'undefined', 'window'
*
* Copyright (c) 2009 Daniel Steigerwald (http://daniel.steigerwald.cz), Mit Style License
@rwjblue
rwjblue / readme.md
Last active May 13, 2016 18:10
Guide to using drip with JRuby

#Overview drip is an awesome command line tool that can be used to dramatically lower perceived JVM startup time. It does this by preloading an entirely new JVM process\instance and allowing you to simply use the preloaded environment. This has extraordinary results with jruby.

We reduced time to run rake environment from 13 seconds to a mere 3.5 seconds. This is actually at or near MRI 1.9.3p327 (with falcon patch) speeds!

Adding a few addition jruby options will reduce startup time even further (down to 1.69 seconds).

#Install Drip Install drip if you haven't already (see https://github.com/flatland/drip)

source 'https://rubygems.org'
gem 'multi_json'
@headius
headius / check_thread_alloc.rb
Created December 29, 2011 12:42
Monitoring per-thread allocation using JRuby and java.lang.management.ThreadMXBean
require 'java'
require 'jruby'
thread_bean = java.lang.management.ManagementFactory.thread_mx_bean
t1 = Thread.new do
a = nil
loop do
a = 'foo'
end
@headius
headius / 0.soft_ordering.diff
Last active September 6, 2016 13:59
Four impls of thread-safe Array#at for JRuby
diff --git a/core/src/main/java/org/jruby/RubyArray.java b/core/src/main/java/org/jruby/RubyArray.java
index 04fbeef..1c32bb39 100644
--- a/core/src/main/java/org/jruby/RubyArray.java
+++ b/core/src/main/java/org/jruby/RubyArray.java
@@ -71,6 +71,7 @@ import org.jruby.util.io.EncodingUtils;
import java.io.IOException;
import java.lang.reflect.Array;
+import java.lang.reflect.Field;
import java.util.Arrays;
# Monkeypatch to disable connection pooling in ActiveRecord
module ActiveRecord
module ConnectionAdapters
class ConnectionPool
def checkout
c = ActiveRecord::Base.send(spec.adapter_method, spec.config.dup)
c.verify!
c
end
@headius
headius / gist:2a8de5eb6adb115acb4649b698e2f6d3
Created February 1, 2017 06:30
mandelbrot(750) on JRuby with and without a tweaked Graal
~/projects/graal-core $ jruby -v mandelbrot.rb
jruby 9.1.8.0-SNAPSHOT (2.3.1) 2017-01-25 2b97d78 Java HotSpot(TM) 64-Bit Server VM 9-ea+152 on 9-ea+152 +indy +jit [linux-x86_64]
1.4988730000000001
0.875144
0.6610520000000001
0.666915
0.67083
0.658069
0.6749970000000001
0.667617