Donnerstag, 2. April 2009

format output in ruby

with #{ }

puts "Text is #{["Test 1", "Test 2"][1]}"
=>Text is Test 2

["Test 1", "Test 2"]
create array with "Test 1" and "Test 2"

["Test 1", "Test 2"][1]
choose second item [1]

print out as variable with #{}

simple outputs through strings objects


see info: ri String#%

format%argument => string

"%05d" % 123       fill with zero on numbers
=> "00123"

"%05s" % 123 do space
=> " 123"

"%-05s" % 123
=> "123 "

"%-5s: %08x" % [ "ID", self.object_id ]
=> "ID : fdbe224ac"
"%10.3f" % 123
=> " 123.000"

"%-10.3f" % 123
=> "123.000 "



output with sprintf analog to sprintf in c

see info: ri sprintf

format(format_string [, arguments...] ) => string
sprintf(format_string [, arguments...] ) => string

sprintf("%d %04x", 123, 123)
=> "123 007b"
sprintf("%08b '%4s'", 123, 123)
=> "01111011 ' 123'"
sprintf("%1$*2$s %2$d %1$s", "hello", 8)
=> " hello 8 hello"
sprintf("%1$*2$s %2$d", "hello", -8)
=> "hello -8"
sprintf("%+g:% g:%-g", 1.23, 1.23, 1.23)
=> "+1.23: 1.23:1.23"
sprintf("%u", -123)
=> "..4294967173"

i,d integer
x hex
s string
b bit
e,f,g floating
%x$y x which argument, y what (i,d,s,..)
%1$*2$s argument 1 with length of argument 2 (string)

Montag, 23. Februar 2009

ruby infos

http://www.rubyinside.com/passenger-stack-quickly-install-a-full-ruby-and-passenger-stack-1533.html

Passenger-Stack is a set of scripts for the provisioning tool Sprinkle that make installing a full Ruby, Apache and Passenger-based stack almost a one-line task. It'll take almost any UNIX-y (correction: Ubuntu / Debian) server of your choice from a generic install through to deploying Rack-based apps (including those built with Rails, Merb, Sinatra, and Ramaze).


=>
Sprockets: A Ruby-powered JavaScript dependency library from 37signals

Building a Ruby Gem (From Scratch) Using Behavior Driven Development

Montag, 26. Januar 2009

SECURITY macchanger

http://www.fedorawiki.de/index.php/MACChanger

Montag, 19. Januar 2009

COMP cdrecord

cdrecord -scannbusscsibus1:
1,0,0 100) 'HL-DT-ST' 'DVD+-RW GSA-H31L' 'W616' Removable CD-ROM
1,1,0 101) *


cdrecord -v -pad dev=1,0,0 speed=8 blub.iso

Donnerstag, 8. Januar 2009

anonym in p2p

RShare, www.stealthnet.de

RShare node, RShareID

Java SQL derby

derby -> apache

System.setProperty("derby.system.home", "dbname.db");

Connection conn = DriverManager.getConnection("jdbc:derby:test_db;create=true");

try {
Statement s = conn.createStatement();
s.execute("CREATE TABLE data (id INT, text VARCHAR(100), PRIMARY KEY (id))");
s.execute("INSERT INTO data VALUES (1, 'Hallo')");
s.execute("INSERT INTO data VALUES (2, 'Blub')");

ResultSet rs = s.exeucteQuery("SELECT text FROM data WHERE id=1");

while (rs.next()) {
String text = rs.getString("text");
System.out.println(text);
}
} finally {
conn.close();
}

Java SQL

java.sql.*

connecting to Driver Interface
try {
class.forName("com.mysql.jdbc.Driver").newInstance();
} catch ( Exception e) { ... }

Connection cn = DriverManager.getConnection("jdbc:mysql://localhost/test?user=bla&password=bla");

SQLException ex;
ex.getMessage().ex_getSQLState()
ex.getErrorCode()

Statement st = cn.createStatement();
ResultSet rs = st.executeQuery("SELECT ...");

if( st.execute("SELECT ..."))
rs = st.getResultSet();


rs.close(); st.close();