Skip to content

Instantly share code, notes, and snippets.

View coder36's full-sized avatar

Mark Middleton coder36

  • Newcastle
View GitHub Profile
@coder36
coder36 / gist:6d3e84c22f1b4da386ce
Created January 13, 2015 14:14
Hello World encoding to binary and back
"Hello world".bytes.map { |b| b.to_s(2).rjust(8, '0') }.join.to_i(2).to_s(2).scan(/.+?(?=.{8}*\z)/).map {|s| s.to_i(2).chr}.join
@coder36
coder36 / gist:94aa8fc1c72e5a639da7
Created November 19, 2014 14:52
When I saw this scala code snippet for the first time...

Circa 2010, when I saw this scala code snippet for the first time, my mind was blown at the possibilities...

object WhileDemo {
  def main( args: Array[String]): Unit = {
    var i = 1
    While( i < 10 ) {
      println( i )
      i+=1
    }

}

@coder36
coder36 / gist:bf4ca14cf9f1f411cdbe
Created November 19, 2014 14:30
Scala 'using' implementation
object UsingDemo {
def main( args : Array[String] ) {
using( new A() ) { a =>
a.print("Hello World " )
}
}
@coder36
coder36 / gist:4a094703384ba4238ced
Created October 3, 2014 23:06
Installing Jruby on Ubuntu Trusty

When using rvm to install jruby on Ubuntu Trusty, you will need:

  • 2048mb memory (if you have less than this then mvn exists with some random error!)
  • mvn installing and available on the path.

To create fake RPM's, use fpm...

If the RPM's were created correctly in the firstplace, then the epock should be set to 0. In the scenario below, the epochs had been set to the current unin time. Strangely, you can not just set it to 9999999999? You may need to employ different strategies to get the fake package to 'win' the version battle over existing rpm's:

    mkdir -p /tmp/fake_package
    fpm -s dir -t rpm -n grpahite -v 999999999 --epoch `date +%s` -f -a noarch -C /tmp/fake_package ./
    fpm -s dir -t rpm -n logstash -v 0.0.1 --epoch `date +%s` --iteration 999 -f -C /tmp/fake_package ./
    fpm -s dir -t rpm -n sensu -v 0.0.1 --epoch `date +%s` --iteration 999 -f -C /tmp/fake_package ./

fpm -s dir -t rpm -n uchiwa -v 0.0.1 --epoch date +%s --iteration 999 -f -C /tmp/fake_package ./

@coder36
coder36 / gist:6f2a9740ca58911519bf
Created September 4, 2014 12:22
RPM version info

RPM version info:

    rpm -qi zlib

rpm -q zlib --queryformat %{version}-%{release}

@coder36
coder36 / gist:220e7ba6c9c326988d3c
Created June 18, 2014 18:21
Bit counter algorithm

Counts the number of bits in an array. Assumes array of 8 bit values

def count_bits a
  a.inject(0) do |total, n| 
    (0...8).each do |j|
      total = total + ( (n>>j) & 0x01 )
    end
    total
  end

end

@coder36
coder36 / gist:105240448ad95ec2aa3c
Last active August 29, 2015 14:01
Ansible Spike

Setup

[ansible github] (https://github.com/ansible/ansible)

sudo yum install rpm-build make python2-devel asciidoc python-setuptools PyYAML python-crypto2.6 python-httplib2  python-jinja2  python-keyczar sshpass
git clone git://github.com/ansible/ansible.git
cd ./ansible
git checkout release1.6.2

make rpm