Skip to content

Instantly share code, notes, and snippets.

View justahero's full-sized avatar

Sebastian Ziebell justahero

View GitHub Profile
@justahero
justahero / consolg_log.as
Created July 12, 2012 15:52
This fixed logging of text to the browser's Javascript console for me
// This function logs a message to the browser's Javascript console
// Tested with latest flash debug player (11.3.300.257) and latest Chrome (20.0.1132.57)
// see http://stackoverflow.com/questions/864155/see-trace-of-flash-when-running-in-browser for original function
public static function log(msg:String, caller:Object = null) : void {
var str:String = "";
if (caller) {
str = getQualifiedClassName(caller);
str += ":: ";
}
str += msg;
@justahero
justahero / Rakefile
Created March 17, 2013 20:26
After digging into Rake and using tasks to compile and run a C++ project I learned that it can also be used to create tasks dynamically. My goal then was to create Rake tasks for all sample projects that reside in a specific project folder, where each sub folder represents a single sample. I am not sure if this excerpt runs perfectly but it shou…
require 'rake/task'
namespace :samples do
# find all sub folders in directory, each sub folder represents a sample project
Dir.glob('path/to/samples/*').select do |file|
if File.directory?(file)
app_name = file.split('/').last
desc "Run sample #{file}"
task app_name do
Rake::Task['code:compile'].invoke # some task to compile code & samples
@justahero
justahero / remove_elasticsearch.sh
Created February 7, 2014 19:17
Remove ElasticSearch installation on CentOs
#!/bin/sh
set -e
/etc/init.d/elasticsearch stop
/usr/local/share/elasticsearch/bin/service/elasticsearch remove
rm -rf /usr/local/share/elasticsearch
@justahero
justahero / git-aliases.md
Last active August 29, 2015 13:57
Git aliases

My git aliases

Most of the git aliases are standard abbrevations. Similar to other alias definitions I use a different output format (source).

On projects with more than a couple of authors it might be useful to show only commits by oneself: git lg-me

One alias that I found very useful especially when following the Github workflow is to check which pull requests got merged into the main development branch. It's also useful to see how many PRs were added inbetween releases / tags.

git log-grep v0.1.0..v.2.1
@justahero
justahero / define_method_test
Last active August 29, 2015 14:04
Small examples of how to add functions to a class with define_method
# Defines the method say_hello on an instance object
# this is very similar to:
# def say_hello
# puts "Hello"
# end
#
class Test
define_method(:say_hello){ puts "Hello" }
end
class Test
def add_hello
self.class.send(:define_method, :say_hello){ puts "Hello world" }
end
end
t = Test.new
t.say_hello # => NoMethodError: undefined method `say_hello'
t.add_hello # => adds the function at runtime
t.say_hello # => "Hello world"
@justahero
justahero / virtus_setter.rb
Last active August 29, 2015 14:10
Virtus example to overload attribute setter in a Module does not work
# Virtus example to overload an existing setter
require 'virtus'
module A
include Virtus.module
attribute :foo, String, default: 'FOO'
end
module B
@justahero
justahero / fizz_buzz.rb
Last active August 29, 2015 14:22
FizzBuzz in Ruby
# using arrays
(1..100).each{|n|a=[n%3==0&&'fizz',n%5==0&&'buzz'].reject{|n|!n}.join;puts a.empty? ? n:a}
(1..100).each{|n|a=[n%3!=0?'':'fizz',n%5!=0?'':'buzz'].join;puts a.empty?? n:a}
# only strings
(1..100).each{|n|a=(n%3>0?'':'fizz')+(n%5>0?'':'buzz');puts a.empty?? n:a}
# using hashes
(1..100).each{|n|a=Hash["fizz",3,"buzz",5].map{|k,v|k if n%v==0}.join;puts a.empty?? n:a}
@justahero
justahero / Vagrantfile
Last active March 5, 2018 16:39 — forked from ampedandwired/Vagrantfile
Configure VM / docker with company proxy CNTLM
# put the following content into ~/.vagrant/Vagrantfile
# install plugin vagrant-proxyconf: vagrant plugin install vagrant-proxyconf
VAGRANTFILE_API_VERSION = "2"
def get_proxy_url
# Doesn't support different proxies for different protocols at present
host_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY'] || ENV['https_proxy'] || ENV["HTTPS_PROXY"]
if host_proxy
uri = URI(host_proxy)
@justahero
justahero / default.yaml
Created September 8, 2017 10:02
Modified beaker box configuration to be able to run Elasticsearch successfully
HOSTS:
centos-7-x64-master:
roles:
- master
- agent
platform: el-7-x86_64
hypervisor: vagrant
box: puppetlabs/centos-7.2-64-nocm
vagrant_memsize: 2048 # increase memory or OutOfMemoryError will occur
vagrant_cpus: 2 # to speed things up a little