Geerd Wilders: Enough is enough

Mar 28
2008

Scalar || List context

Feb 12
2008

Perl

 $a  = ("a", "b", "c"); # $a is "c" - the last element
($a) = ("a", "b", "c"); # $a is "a" - the first element

Ruby

 obj        = ["a", "b", "c"] # obj is Array - ["a", "b", "c"]
 obj, b, c = ["a", "b", "c"] # obj is String - "a"

Lotto checking script

Feb 12
2008

The idea comes from http://www.waider.ie/hacks/workshop/perl/lotto.pl script.

Should I be so wasteful? No:

irb

my_numbers       = [1,2,3,4,5,6]
winning_numbers = [1,2,3,41,42,43]
 
result = 6 - (winning_numbers - my_numbers).size
 
puts "#{result} " +
  if not result.eql? 0
    "hits"
  else
    "hit"
  end

Sort By Part Of Filename

Jan 12
2008

Assume that we have directory, containing files like:

part_1.txt
part_2.txt
part_100.txt
part_200.txt

In case that we are interested in /(\d+)\.\w+$/ as part of the sorting criteria:

Perl

# short but unefficient
@a = sort {($a =~ /(\d+)\.\w+$/)[0] < => ($b =~  /(\d+)\.\w+$/)[0]} < *>;

Ruby

regex = Regexp.new(/(\d+)\.\w+$/)
 
# enum.sort {| a, b | block } => array
Dir["*"].grep(regex).sort do |a, b|
  a.match(regex)[0].to_i < => b.match(regex)[0].to_i
end
 
# enum.sort_by {| obj | block } => array
Dir["*"].grep(regex).sort_by do |name|
  name.match(regex)[1].to_i
end

getting root acccess without sudo

Dec 29
2007
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "sys/types.h"
#include "unistd.h"
#include "stdlib.h"
#include "stdio.h"
 
int main(int argc, char** argv)
{
    int root_id = 0;
    char *command = argv[1];
 
    if(!command)
        command = "/bin/bash";
 
    setuid(root_id);
    system(command);
    exit(0);
}

root# gcc -o temproot temproot.c
root# chmod +s temproot
nobody$ alias root=’temproot “su – root”’
nobody$ root

Calendar

February 2012
M T W T F S S
« Sep    
 12345
6789101112
13141516171819
20212223242526
272829  

Tags