Skip to content

Instantly share code, notes, and snippets.

@djo
djo / run.sh
Last active January 27, 2020 04:35
Handling of UNIX-signals in Erlang/Elixir is not supported, this script provides start-stop management with handling TERM signal for Docker installation.
#!/usr/bin/env bash
set -x
term_handler() {
echo "Stopping the server process with PID $PID"
erl -noshell -name "term@127.0.0.1" -eval "rpc:call('app@127.0.0.1', init, stop, [])" -s init stop
echo "Stopped"
}
trap 'term_handler' TERM INT
@djo
djo / build.sbt.md
Last active August 29, 2015 14:14
Resolve conflicts in Apache Spark with Parquet format

Conflicts in the sbt dependencies when adding parquet-format:

java.lang.RuntimeException: deduplicate: different file contents found in the following:
path-to-cache/org.slf4j/slf4j-api/jars/slf4j-api-1.7.9.jar:META-INF/maven/org.slf4j/slf4j-api/pom.properties
path-to-cache/com.twitter/parquet-format/jars/parquet-format-2.2.0-rc1.jar:META-INF/maven/org.slf4j/slf4j-api/pom.properties

To resolve it exclude slf4j-api/pom.properties from parquet-format package:

@djo
djo / trace_func.rb
Created November 14, 2014 13:37
Handle ruby trace
proc_object = proc do |event, file, line, id, binding, klass|
puts "#{event} in #{file}/#{line} #{id} #{klass}"
end
set_trace_func(proc_object)
@djo
djo / boot.rb
Created May 15, 2014 08:41
Setup Syck YAML engine in Ruby 2, Rails, DelayedJob
require 'rubygems'
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
# YAML Syck engine support was dropped in Ruby 2.0 and it's available only by a gem 'syck'.
# Some gems (delayed_job[1] for instance) have YAML extensions depending on the engine.
# Switching to the Syck engine should be done in boot.rb before loading all gems in application.rb:
@djo
djo / deploy.rb
Last active December 21, 2023 07:08
Rails, Nginx, XSendfile, and X-Accel-Mapping
# Symlink the shared protected folder
run "ln -nfs #{shared_path}/protected #{latest_release}/protected"
@djo
djo / towers.rb
Created January 22, 2014 13:58
The classic problem of the Towers of Hanoi.
require 'minitest/autorun'
class Towers
class CantPlaceError < StandardError; end
attr_accessor :from, :to
def initialize(from, to)
@from = from
@to = to
@djo
djo / dequeue.java
Last active April 9, 2017 18:22
Mistake in the Cracking Coding Interview 5th edition book: loitering problem in the queue implementation.
// Enhanced and fixed the dequeue method
if (first == null) return null;
Object item = first.data;
first = first.next;
if (first == null) last = null;
return item;
@djo
djo / fsarchiver
Last active December 22, 2015 05:29
Dump a partition with fsarchiver
# http://www.fsarchiver.org/QuickStart
sudo apt-get install fsarchiver
# Find out what partition is used for the current folder and choose another partition for the dump
df -h .
df -h
# Re-mount /dev/md2 partition to read only mode
sudo mount -o remount,ro /dev/md2
sudo fsarchiver savefs ./ubuntu-md2.fsa /dev/md2
@djo
djo / tar.txt
Created August 28, 2013 08:30
When you don't have time to read `man tar`.
# Create the archive
tar -zcvf archive.tar.gz /home/dir
# Restore the archive
tar -zxvf archive.tar.gz
tar -zxvf archive.tar.gz -C /tmp
@djo
djo / devise_integration.rb
Created March 6, 2013 11:39
Speed up capybara specs by setting user session directly in the app. To have access to the rack session use https://github.com/railsware/rack_session_access.
def fast_log_in
user = Factory.create(:user)
warden_key = User.serialize_into_session(user).unshift('User')
page.set_rack_session(:'warden.user.user.key' => warden_key)
user
end