FaziBear
Gloomy Programming Adventures
Monday, February 23, 2009

What's wrong with merb ?

Posted In: , . By FaziBear

If you get this ...
FATAL: The gem data_objects (= 0.9.11, runtime), [] was not found
... try this ...
sudo gem install launchy
... and everything will be fine ...

 
Monday, December 8, 2008


require 'rubygems'
require "inline"
class SMS
class << self
inline do |builder|
builder.add_compile_flags '-x objective-c', '-framework IOKit'
builder.include "<IOKit/IOKitLib.h>"
builder.c %q{
VALUE values(){

struct data {
unsigned short x;
unsigned short y;
unsigned short z;
char pad[34];
};

kern_return_t result;

mach_port_t masterPort;
IOMasterPort(MACH_PORT_NULL, &masterPort);
CFMutableDictionaryRef matchingDictionary = IOServiceMatching("SMCMotionSensor");

io_iterator_t iterator;
result = IOServiceGetMatchingServices(masterPort, matchingDictionary, &iterator);

if(result != KERN_SUCCESS) {
return rb_str_new2("Error");
}

io_object_t device = IOIteratorNext(iterator);
IOObjectRelease(iterator);
if(device == 0){
return rb_str_new2("Error");
}

io_connect_t dataPort;
result = IOServiceOpen(device, mach_task_self(), 0, &dataPort);
IOObjectRelease(device);

if(result != KERN_SUCCESS) {
return rb_str_new2("Error");
}

IOItemCount structureInputSize;
IOByteCount structureOutputSize;

struct data inputStructure;
struct data outputStructure;
structureInputSize = sizeof(struct data);
structureOutputSize = sizeof(struct data);

memset(&inputStructure, 1, sizeof(inputStructure));
memset(&outputStructure, 0, sizeof(outputStructure));

result = IOConnectMethodStructureIStructureO(
dataPort,
5,
structureInputSize,
&structureOutputSize,
&inputStructure,
&outputStructure
);

if(result != KERN_SUCCESS) {
return rb_str_new2("Error");
}

IOServiceClose(dataPort);

VALUE coords = rb_ary_new2(3);
rb_ary_store(coords, 0, INT2FIX(outputStructure.x));
rb_ary_store(coords, 1, INT2FIX(outputStructure.y));
rb_ary_store(coords, 2, INT2FIX(outputStructure.z));

return coords;
}
}
end
end
end
loop do
x,y,z = SMS.values
puts "#{x} #{y} #{z}"
end

 
Thursday, June 5, 2008

Include helpers in controllers

Posted In: , . By FaziBear

Yes, i know!

Helpers are modules that provide methods which are automatically usable in your view.
But somtimes you want to use it in controllers ;)
This is my solution. Helpers are available in module named 'Helpers', so they don't brake anything. All rails helpers and named routes are included by default.
This is simple usage:

class ExampleController < ApplicationController
include_helper ApplicationHelper, PicturesHelper

def show
...
flash[:notice] = Helpers::flash_with_picture('Hello from helper')
...
end
end
And method to add to ApplicationController class.

class ApplicationController < ActionController::Base
def self.include_helper(*args)
require 'action_controller/integration'
class_eval do
helpers = const_defined?('Helpers') ? const_get('Helpers') : Module.new do
@@controller = ActionController::Integration::Session.new
def self.method_missing(method, *args, &block)
if @@controller && method.to_s =~ /_path$|_url$/
@@controller.send(method, *args, &block)
else
raise NoMethodError, "undefined method `#{method}' for #{self}"
end
end
end
ActionView::Helpers.constants.each do |constant|
helpers.extend ActionView::Helpers.const_get(constant) if ActionView::Helpers.const_get(constant).instance_of?(Module)
end
if args.instance_of?(Array)
args.each do |helper|
helpers.extend helper if helper.instance_of?(Module)
end
elsif args.instance_of?(Module)
helpers.extend args
end
const_set( 'Helpers', helpers ) unless const_defined?('Helpers')
end
end
end

 
Tuesday, April 29, 2008

GEdit With Multi Terminal

Posted In: , . By FaziBear

GEdit is nice developer editor for GNOME. Textmate like snippets, file browser and embedded terminal. Last one is a nice feature, but default plugin gives you only one terminal. But wait, plugins are written in python. This is my third attempt to modify python code... It was not so bad, after few print(), dir(), and id() I can add and remove terminal windows within gedit :)

How to install ? Copy all files to ~/.gnome2/gedit/plugins, disable terminal plugin, restart gedit and enable mterminal plugin.

How to use it ? To add new terminal right-click on terminal window and choose 'New Terminal'. If you want to remove it, right-click and choose 'Remove Terminal'.

Plugin/Sources are located here.

I hope you like it.

 
Friday, March 14, 2008

UWA Google Suggest

Posted In: , , . By FaziBear

Google Suggest is now UWA style widget. Check this out.