Skip to content

Instantly share code, notes, and snippets.

View pbosetti's full-sized avatar
:octocat:

Paolo Bosetti pbosetti

:octocat:
View GitHub Profile
@pbosetti
pbosetti / metatest.rb
Created January 20, 2011 09:59
Metaprogramming test example
#!/usr/bin/env ruby
# metatest
#
# Created by Paolo Bosetti on 2011-01-20.
# Copyright (c) 2011 University of Trento. All rights reserved.
#
def header(string)
border = "=" * string.length
puts
@pbosetti
pbosetti / zlib_test.rb
Created March 30, 2011 23:26
Testing zlib compression on strings
#!/usr/bin/env ruby
# untitled.rb
# Created by Paolo Bosetti on 2011-03-30.
# Copyright (c) 2011 University of Trento. All rights reserved.
require "zlib"
str = ""
100.times do |i|
@pbosetti
pbosetti / asynchronous_trap.rb
Created April 21, 2011 00:16
Asynchronously trap signals
c = Thread.current
Signal.trap("SIGINT") do
c.wakeup
end
while true
sleep
puts "wake"
end
@pbosetti
pbosetti / timer.rb
Created April 21, 2011 01:56
Recurring process triggered by SIGALARM via ualarm FFI mapping
#!/usr/bin/env ruby
# untitled.rb
# Created by Paolo Bosetti on 2011-04-20.
# Copyright (c) 2011 University of Trento. All rights reserved.
require "rubygems"
require 'ffi'
class Array
def mean
@pbosetti
pbosetti / shared.rb
Created April 28, 2011 18:35
IPC shared memory access via FFI
#!/usr/bin/env ruby
# untitled.rb
# Created by Paolo Bosetti on 2011-04-22.
# Copyright (c) 2011 University of Trento. All rights reserved.
require "rubygems"
require 'ffi'
module Shared
@pbosetti
pbosetti / charter_client.rb
Created September 16, 2011 13:00
Charter App client library
#!/usr/bin/ruby
# untitled.rb
# Created by Paolo Bosetti on 2011-09-02.
# Copyright (c) 2011 University of Trento. All rights reserved.
require "socket"
module Charter
BASE_PORT = 2000
@pbosetti
pbosetti / auto_mouse.rb
Created September 29, 2011 10:12
Mouse clicks automation
#!/usr/bin/env ruby
require 'ffi'
module Mouse
extend FFI::Library
ffi_lib '/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics'
class CGPoint < FFI::Struct
@pbosetti
pbosetti / stama.rb
Created November 17, 2011 10:16
Simple State Machine
#!/usr/bin/env ruby
# stama.rb
# Created by Paolo Bosetti on 2011-10-07.
# Copyright (c) 2011 University of Trento. All rights reserved.
class State
attr_accessor :id, :next, :machine
def initialize(id, &action)
#!/bin/sh
if [[ $EUID -ne 0 ]]; then
echo 1>&2
echo 1>&2
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" 1>&2
echo "! This script must be run as root! !" 1>&2
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" 1>&2
echo
exit 1
fi
#!/bin/bash
bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
echo
echo "Setting up environment"
echo "[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function" >> .bash_profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
echo