Skip to content

Instantly share code, notes, and snippets.

View glejeune's full-sized avatar

Gregoire Lejeune glejeune

View GitHub Profile
@glejeune
glejeune / gist:664178
Created November 5, 2010 13:43
Execute with Root privileges
- (void)execute:(NSString *)cmd {
NSString *appScript = [NSString stringWithFormat:@"do shell script \"%@\" with administrator privileges", cmd];
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:appScript];
NSDictionary *errorInfo = nil;
NSAppleEventDescriptor *data = [script executeAndReturnError:&errorInfo];
if( data == nil ) {
// Hum... Something happend, dude!
NSLog(@"ERROR : %@", [errorInfo objectForKey:NSAppleScriptErrorMessage]);
} else {
@glejeune
glejeune / lisp.rb
Created September 2, 2010 09:35 — forked from dahlia/lisp.rb
# 30 minutes Lisp in Ruby
# Hong MinHee <http://dahlia.kr/>
#
# This Lisp implementation does not provide a s-expression reader.
# Instead, it uses Ruby syntax like following code:
#
# [:def, :factorial,
# [:lambda, [:n],
# [:if, [:"=", :n, 1],
# 1,
IoGraphViz
gv := IoGraphViz clone with("G")
hello := gv addNode("hello", nil)
world := gv addNode("world", nil)
gv addEdge(hello, world)
options := Map clone do(
require "rubygems"
require "graphviz"
g = GraphViz::new( "G", :type => "graph" )
n1 = g.add_node( "A" )
n2 = g.add_node( "B" )
n3 = g.add_node( "C" )
e1 = g.add_edge( n1, n2 )
e1[:dir] = 'forward'
e2 = g.add_edge( n1, n3 )
// shortcut.m
//
// compile:
// gcc shortcut.m -o shortcut.bundle -g -framework Foundation -framework Carbon -dynamiclib -fobjc-gc -arch i386 -arch x86_64
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h>
@interface Shortcut : NSObject
require "shortcut"
require 'hotcocoa'
class Application
include HotCocoa
def start
application :name => "Shortcut" do |app|
app.delegate = self
<img src="http://dotgraph.net/embed/[mysite]/image/?src=http://mysite.com/my_graph.dot">
require 'java'
require 'rubygems'
rb_root = File.dirname(__FILE__)
app_root = File.dirname(__FILE__)+'/..'
Dir[app_root+"/*.jar"].each { |jar| require jar }
require 'rack'
Dir[app_root+"/Java/jetty/*.jar"].each { |jar| require jar }
@glejeune
glejeune / timer.rb
Created December 22, 2009 17:46
A very very simple timer
require 'rubygems'
require 'eventmachine'
class Timer
def initialize
@run = false
@timeout_proc = nil
end
# Run <tt>blk</tt> every <tt>every</tt> seconds during <tt>during</tt> seconds
# (The MIT License)
#
# Copyright (c) 2009 Grégoire Lejeune
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# 'Software'), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to