Name: Anonymous 2008-06-04 10:39
GO!
#!/usr/bin/env php
<?php
$opts = getopt("hf:o:");
if (isset($opts['h']) || !isset($opts['f'])) {
$usage = <<<EOD
Usage: $argv[0] [-h] -f file.bin [-o file.png]
EOD;
fwrite(STDERR, $usage);
die();
}
$f = @ file_get_contents($opts['f']);
if (!$f) {
fwrite(STDERR, "Invalid file.\n");
die();
}
$len = strlen($f);
$data = $len . "\0" . basename($opts['f']) . "\0" . $f;
$size = ceil(sqrt(strlen($data) / 3));
$img = imagecreatetruecolor($size, $size);
for ($a = 0; $a < $size; ++$a) {
for ($b = 0; $b < $size; ++$b) {
if (isset( $data[((($a * $size) + $b) * 3) ])) {
$R = ord($data[((($a * $size) + $b) * 3) ]);
} else {
$R = 255;
}
if (isset( $data[((($a * $size) + $b) * 3) + 1])) {
$G = ord($data[((($a * $size) + $b) * 3) + 1]);
} else {
$G = 255;
}
if (isset( $data[((($a * $size) + $b) * 3) + 2])) {
$B = ord($data[((($a * $size) + $b) * 3) + 2]);
} else {
$B = 255;
}
$c = imagecolorallocate($img, $R, $G, $B);
imagesetpixel($img, $b, $a, $c);
}
}
header ("Content-type: image/png");
if (!isset($opts['o']) || empty($opts['o'])) {
$opts['o'] = null;
} else {
echo "Writing image to ${opts['o']}.\n";
}
imagepng($img, $opts['o'], 9);
?>#!/usr/bin/env php
<?php
$opts = getopt("hf:o");
if (isset($opts['h']) || !isset($opts['f'])) {
$usage = <<<EOD
Usage: $argv[0] [-h] -f file.bin [-o]
o: Extracts file to original filename instead of stdout.
EOD;
fwrite(STDERR, $usage);
die();
}
$img = @ imagecreatefrompng($opts['f']);
if (!$img) {
fwrite(STDERR, "Invalid file.\n");
die();
}
$x = imagesx($img);
$y = imagesy($img);
$o = "";
for ($a = 0; $a !== $x; ++$a) {
for ($b = 0; $b !== $y; ++$b) {
$c = imagecolorat($img, $b, $a);
$o .= chr(($c >> 16) & 0xFF) . chr(($c >> 8 ) & 0xFF) . chr($c & 0xFF);
}
}
list($l, $name, $f) = explode("\0", $o, 3);
if (!is_numeric($l) || empty($name) || empty($f)) {
fwrite(STDERR, "Invalid file.");
die();
}
if (isset($opts['o'])) {
echo "Writing $l KiB to $name.\n";
file_put_contents($name, substr($f, 0, $l));
} else {
echo substr($f, 0, $l);
}
?>
fact n = product [1..n]
# This code is intended to convert AngelCode BMFont font files
# (.fnt) into a header file, for use with Nintendo DS homebrew
# development.
# This is intended to be used with the object files created by bin2o
# in devkitPro. If the font name has spaces in it, this will probably break.
# Try using underscores instead.
# Another feature provided is that the kerning nodes are sorted to allow
# binary search of kerning nodes, if you don't want to go to the effort of
# putting them in a proper data structure.
# You are expected to define the FontInfo, CharInfo, and KerningInfo structures yourself.
for file in ARGV
lines = File.open(file, "r") do |f|
f.read
end
face = nil
size = nil
width = nil
height = nil
line_height = nil
chars = []
kerning = []
# This could be better, but it works...
for line in lines
m = /(\w+)\s+(.*)/.match(line)
if m
name = m[1]
parts = {}
m[2].split(/\s+/).each do |ma|
ma=ma.split('=')
parts[ma[0]] = ma[1]
end
case name
when "info"
face = parts["face"].gsub(/(^\")|(\"$)/,'');
size = parts["size"].to_i
bold = parts["bold"].to_i
italic = parts["italic"].to_i
when "common"
line_height = parts["lineHeight"].to_i
width = parts["scaleW"].to_i
height = parts["scaleH"].to_i
when "char"
char = []
char << parts["id"] << parts["x"] << parts["y"] << parts["width"] << parts["height"] << parts["xoffset"] << parts["yoffset"] << parts["xadvance"] << parts["page"]
chars << char
when "kerning"
kern = []
kern << parts["first"] << parts["second"] << parts["amount"]
kerning << kern
else
end
end
end
#Sort the kernings by first, then second.
kerning = kerning.map {|k|
k.map{|ki|
ki.to_i
}
}
kerning.sort! do |a,b|
if a[0] != b[0]
a[0] <=> b[0]
elsif a[1] != b[1]
a[1] <=> b[1]
else
0
end
end
# Obviously, modify this part to suit your needs.
# I should probably put the padding value in there too...
File.open(file.gsub(/\.fnt$/,'.h'), "w") do |fh|
fh.puts <<HEADER
#include "types.h"
#include "font.h"
#include "#{face}_#{size}_bin.h"
namespace demo {
FontInfo #{face}#{size} = {
"#{face}", #{size}, #{line_height}, #{bold}, #{italic},
{0,0,0,0},
{0,0,#{width},#{height}},
#{face}_#{size}_bin, #{face}_#{size}_bin_size
};
CharInfo #{face}_#{size}_Chars[#{chars.length}] = {
HEADER
for char in chars
fh.puts " { #{char.join(", ")} },"
end
# End of the characters, start of the kerning nodes.
fh.puts <<MIDDLE
};
KerningInfo #{face}_#{size}_Kerning[#{kerning.length}] = {
MIDDLE
for kern in kerning
fh.puts " { #{kern.join(", ") } },"
end
#End of the file.
fh.puts <<END
};
}
END
end
end
const * const grabs const dick const * const
import Control.Monad.Identity
factorial n | n < 0 = fail "factorial: negative argument."
| otherwise = product [1..n]
fact = runIdentity . factorial
perl < /dev/random
fact (n+0) = product [2..n]
import Control.Monad.Identity
factorial n | n < 0 = fail "factorial: negative argument."
| otherwise = return $ product [1..n]
fact = runIdentity . factorial
#include <limits.h>
#include <stdint.h>
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
#error Please use a compiler that supports the C99 standard to compile this file.
#endif
void sort(uintmax_t *numbers, size_t length){
uintmax_t temp[length], *arrays[2] = {numbers, temp};
for(uint_fast8_t i = 0; i < sizeof(uintmax_t) * CHAR_BIT; ++i)
for(size_t j = 0, start = 0, end = length - 1; j < length; ++j){
if(!(arrays[i & 1][j] & 1 << i))
arrays[i & 1 ^ 1][start++] = arrays[i & 1][j];
if(arrays[i & 1][length - j - 1] & 1 << i)
arrays[i & 1 ^ 1][end--] = arrays[i & 1][length - j - 1];
}}
__STD_C_VERSION__ with the value 199901L) if you use the -std=c99 option, even though it's support of the standard is incomplete.uintmax_t values in O(n) time.
from random import choice
def randsent(x,f):
pbal='bcdfghjklmnpqrstvwxyz'
bal='aeiou'
l=['110','10']
c=[]
z=''
for i in range(x):
for y in range(randint(1,f)):
q=choice(l)
for i in q:
if i=='0':
z+=choice(bal)
else:
z+=choice(pbal)
if i==0:
z.capitalize()
c.append(z)
z=''
r=' '.join(c)
return r+'.'
#!/usr/bin/perl -w
if(!defined($ARGV[0])) {
print "usage gen.pl <grammar file>\n";
exit 1;
}
open(GRAMMAR, "<", $ARGV[0])
or die "cant read from file: $ARGV[0]";
$startsymbol = <GRAMMAR>;
chomp($startsymbol);
print "ss: $startsymbol \n";
while(<GRAMMAR>) {
$rule = $_;
chomp($rule);
# parse the rule
@halves = split('::=', $rule);
$nonterm = $halves[0];
# ignore comments
next if $nonterm =~ /^#.*/;
@rules = split('\|', $halves[1]);
# store nonterminal and possible
# decendents in hash
$cfg{$nonterm} = [@rules];
}
close(GRAMMAR);
# print rules
for $k (sort keys %cfg) {
print "$k ::= ";
for $r (@{$cfg{$k}}) {
print "\t$r |";
}
print "\n";
}
for($l=0; $l<10; $l++) {
print &randstring($startsymbol, 10) . "\n" ;
}
sub randstring {
my ($s,$d) = (@_);
my $c = "";
my $r = "";
my $done = 1;
for($i=0; $i<length($s); $i++) {
$c = substr($s, $i, 1);
if(&inkeys($c)) {
$done = 0;
$r = &randrule($c);
substr($s, $i, 1, $r);
}
}
if($done or $d == 0) {
return $s;
} else {
return &randstring($s, $d-1);
}
}
sub inkeys {
my $k = pop(@_);
for $key (keys %cfg) {
if($key eq $k) {
return 1;
}
}
return 0;
}
sub randrule {
my $k = pop(@_);
my @rules = @{$cfg{$k}};
return $rules[&boundedrand(0, scalar @rules-1)];
}
sub boundedrand {
my $final = pop(@_);
my $init = pop(@_);
return int((rand() * ($final - $init) + $init) + .5);
}
sub binrand {
return int(rand() + .5)
}
E
E::=EF|F
F::=+|-|>|<|.|,|[E]
#include <limits.h>
#define ISQRT(n)\
({ __typeof__(n) r = 0, _n = (n), i = 1;\
i = i << ((sizeof(i) * CHAR_BIT - (0 > ~i ? 2 : 1)) / 2) * 2;\
if(0 > _n) _n = -n;\
for(; i; i >>= 2)\
if(_n >= (i | r)) {\
_n -= i | r;\
r = r >> 1 | i;\
} else r >>= 1;\
r; })
10 INPUT">";P$
20 FOR I=1 TO LEN(P$)
30 I$=MID$(P$,I,1)
40 IF I$="A" THEN A=A+1
50 IF I$="B" THEN A=A-1
60 IF I$="C" THEN PRINT A;
70 NEXT I
80 REMARKABLE