Skip to content

Instantly share code, notes, and snippets.

View glejeune's full-sized avatar

Gregoire Lejeune glejeune

View GitHub Profile
@glejeune
glejeune / foobarqix.sh
Created November 25, 2011 11:52
Yet another FooBarQix solution
#!/bin/sh
_() {
[ $(expr $V % $1) == 0 ] && R=$(echo $R$2)
}
foobarqix() {
_ 3 "Foo";_ 5 "Bar";_ 7 "Qix"
R=$(echo $R$V | sed -e 's/3/Foo/g' | sed -e 's/5/Bar/g' | sed -e 's/7/Qix/g' | sed -e 's/[0-9]//g')
[ "Z$R" == "Z" ] && R=$V
}
(setq *fbq* (make-hash-table))
(setf (gethash 3 *fbq*) "Foo")
(setf (gethash 5 *fbq*) "Bar")
(setf (gethash 7 *fbq*) "Qix")
(defun foo (v) (
let ((div ""))
(maphash #'(lambda (key value)
(cond ((= (mod v key) 0)
(setf div (concatenate 'string value div))

Show me the code

[[7,"Qix"],[5,"Bar"],[3,"Foo"]].inject(_.to_s){|r,d|i,k=d;r[/^/]=(_%i==0)?k:"";r.gsub!(/#{i}/,k);(r[/\D/].nil?)?r:r.tr("0124689","")}

This is Ruby \o/

No! Wait, this one is better :

((f={3=>:Foo,5=>:Bar,7=>:Qix}).sort.collect{|i,j|_%i==0?j:""}+_.to_s.split(//).collect{|c|f[c.to_i]||""}).join.sub(/^$/,_.to_s) #foobarqix
@glejeune
glejeune / Test.java
Created November 22, 2011 19:33
Find a (UNIX) process in Java
import java.lang.Process;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
class Test {
static public class OsProcess {
@glejeune
glejeune / README.md
Created November 6, 2011 19:50
A (very) simple chat service using AMQP

Run

  1. Install and run an AMQP server (RabbitMQ is a good choise)

  2. Install amqp and ncurses-ruby gems

    sudo gem install amqp ncurses-ruby

  3. Run the client

ruby ./amqp-chat.rb

@glejeune
glejeune / ant2gv.rb
Created October 28, 2011 10:46
Generate a graph from an ANT file
#!/usr/bin/env ruby
require 'rubygems'
require 'open-uri'
require 'nokogiri'
require 'graphviz'
require 'getoptlong'
class Ant2Gv
def initialize(build_file, gv_path)
@glejeune
glejeune / inca.sh
Created October 21, 2011 13:39
Find and convert file encoding
#!/bin/sh
get_encoding() {
FILE=$1
file --mime-encoding $FILE | awk '{print $2}'
}
get_type() {
FILE=$1
file $FILE | awk '{print $2}'
@glejeune
glejeune / jConsole.rb
Created August 8, 2011 19:17
A (very) simple Java console
#!jruby
unless RUBY_PLATFORM === "java"
puts "jConsole only works with jRuby"
puts "For more informations, see http://www.jruby.org/"
exit 1
end
require 'readline'
require 'rubygems'
@glejeune
glejeune / gist:1059397
Created July 1, 2011 21:06
BrainF*ck to Ook!
O="Ook. ";o="Ook? ";k="Ook! ";_={">"=>O+o,"<"=>o+O,"+"=>O+O,"-"=>k+k,"."=>k+O,","=>O+k,"["=>k+o,"]"=>o+k};puts (ARGV[0]||"++++++++++[>++++++++>+++++++++++>+++<<<-]>-.>+.----.>+++.").split(//).map{|c|_[c]}.join
@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 {