There's a great opensource option to nintendo wii development.
DevKitPPC from DevKitPro. It provides a lot of example and a great stuff to you start your game.
You can too download any source from wiibrew.org and study it.
The devkitppc use the homebrew channel in a fantastic way to turn the development so ease.
The homebrew channel start to listen a port and you can run any code direct from your PC.
To install the homebrew channel do not need hardware modifications in wii, all can be done using only soft hacks.
I'm currently learning more about wii development, may be I post some really interesting latter like some of my codes running in wii.
domingo, 25 de dezembro de 2011
segunda-feira, 15 de agosto de 2011
Gmail acess via bash - IMAP
I wrote this script to make a way to read you emails from gmail via BASH, some time after I remaked it to a hack script to remote control any O.S. that use bash:
This time only the gmail access... may be I'll post the powerful script someday.
This time only the gmail access... may be I'll post the powerful script someday.
#!/bin/bash
GMAIL_USER="your_gmail_user";
GMAIL_PW="your_password";
AUTH_HASH="$(echo -en "${GMAIL_USER} ${GMAIL_USER} ${GMAIL_PW}" | base64)";
SLEEP_TIME=2;
TOTAL_MESSAGES="$(
openssl s_client -crlf -connect imap.gmail.com:993 < <(
sleep ${SLEEP_TIME}; echo "A01 LOGIN $GMAIL_USER $GMAIL_PW";
sleep ${SLEEP_TIME}; echo "A02 SELECT INBOX";
sleep ${SLEEP_TIME}; echo "A02 LOGOUT";
sleep ${SLEEP_TIME}; echo "";
) 2>&1 | tr -d "\r" | grep -E "^[*] [0-9]* EXISTS$"| sed "s/^[*] \([0-9]*\) EXISTS.*$/\1/g";
)";
TOTAL_MESSAGES_SENDED="$(
openssl s_client -crlf -connect imap.gmail.com:993 < <(
sleep ${SLEEP_TIME}; echo "A01 LOGIN $GMAIL_USER $GMAIL_PW";
sleep ${SLEEP_TIME}; echo "A02 SELECT \"[Gmail]/E-mails enviados\"";
sleep ${SLEEP_TIME}; echo "A02 LOGOUT";
sleep ${SLEEP_TIME}; echo "";
) 2>&1 | tr -d "\r" | grep -E "^[*] [0-9]* EXISTS$"| sed "s/^[*] \([0-9]*\) EXISTS.*$/\1/g";
)";
LAST_MAIL="$(
openssl s_client -crlf -connect imap.gmail.com:993 < <(
sleep ${SLEEP_TIME}; echo "A01 LOGIN $GMAIL_USER $GMAIL_PW";
sleep ${SLEEP_TIME}; echo "A02 SELECT INBOX";
sleep ${SLEEP_TIME}; echo "A05 FETCH $TOTAL_MESSAGES ALL";
sleep ${SLEEP_TIME}; echo "A06 FETCH $TOTAL_MESSAGES:$TOTAL_MESSAGES BODY[TEXT]";
sleep ${SLEEP_TIME}; echo "A08 store $TOTAL_MESSAGES +FLAGS (\\Deleted)";
sleep ${SLEEP_TIME}; echo "a09 expunge";
sleep ${SLEEP_TIME}; echo "A02 SELECT \"[Gmail]/E-mails enviados\"";
sleep ${SLEEP_TIME}; echo "A08 store 1:$TOTAL_MESSAGES_SENDED +FLAGS (\\Deleted)";
sleep ${SLEEP_TIME}; echo "A09 expunge";
sleep ${SLEEP_TIME}; echo "A02 LOGOUT";
sleep ${SLEEP_TIME}; echo "";
) 2>&1 | tr -d "\r"
)"
SUBJECT="RES: $(echo -e "$LAST_MAIL" | grep ENVELOPE | sed 's/^* [0-9]* FETCH (ENVELOPE ("[^"]*"[ ]"\([^"]*\)".*/\1/g')";
DEST_ADDR="$(echo -e "$LAST_MAIL" | grep ENVELOPE | sed 's/^* [0-9]* FETCH (ENVELOPE .* (("[^"]*" NIL "\([^ ]*\)" "\([^"]*\)".*/\1@\2/g')"
# CODE_TO_RUN="$(echo -e "$LAST_MAIL" | sed -n "/^# NOISSES_KCAH_TRATS #$/,/^# NOISSES_KCAH_DNE #$/p")";
CODE_TO_RUN="$(echo -e "$LAST_MAIL" | tr -d "\n" | grep "NOISSES_KCAH_TRATS" | sed "s/.*# NOISSES_KCAH_TRATS #\(.*\)# NOISSES_KCAH_DNE #.*/\1/g" | xxd -r --ps | rev )";
[ "$DEST_ADDR" == "mailer-daemon@google.com" ] && break;
grep "Delivery to the following recipient failed permanently" <( echo -e "${LAST_MAIL}" ) && break;
(( ${TOTAL_MESSAGES:=0} == 0 )) && break;
MAIL_BODY="$(
{
[ echo -e "
# ---------------------------------------------------------- #
# RESPONSE VIA BASH #
# --------------------- ORIGINAL MESSAGE ------------------- #
\n${LAST_MAIL}
";
}
)";
openssl s_client -crlf -connect smtp.gmail.com:465 < <(
sleep $SLEEP_TIME; echo "ehlo ${GMAIL_USER}";
sleep $SLEEP_TIME; echo "AUTH PLAIN ${AUTH_HASH}";
sleep $SLEEP_TIME; echo "mail from:<${GMAIL_USER}@gmail.com>";
sleep $SLEEP_TIME; echo "rcpt to:";
sleep $SLEEP_TIME; echo "rcpt to:<${DEST_ADDR}>";
sleep $SLEEP_TIME; echo "DATA";
sleep $SLEEP_TIME; echo "From: ${GMAIL_USER}";
sleep $SLEEP_TIME; echo "Subject: $SUBJECT";
sleep $SLEEP_TIME; echo "To: ${DEST_ADDR}";
sleep $SLEEP_TIME; echo "";
sleep $SLEEP_TIME; echo -e "${MAIL_BODY}";
sleep $SLEEP_TIME; echo "";
sleep $SLEEP_TIME; echo ".";
sleep $SLEEP_TIME; echo "quit";
sleep $SLEEP_TIME;
) 2>&1 | cat - > /dev/null
terça-feira, 3 de maio de 2011
Running various commands in bash with limits
Running various commands in bash with limits
# Run various commands at sametime in bash
#!/bin/bash
NUM_MAX_THREADS=200;
IN_FILE="filein.txt";
OUT_FILE="fileout.txt";
CURR_LINE=0;
SECONDS=0;
SECONDS_AVG=0;
TOTAL_LINES=$(cat $IN_FILE | wc -l);
LINE_START_AT="$1";
# echo the time statistics
time (
# read the in file
cat $IN_FILE |
# get the row,
while read LINE;
do
# jumps at the start line
if [[ $CURR_LINE -lt $LINE_START_AT ]]; then
echo "Jumping line... $(( CURR_LINE++ ))";
continue;
fi;
# if don't got processed
if [[ $(grep $LINE $OUT_FILE|wc -l) -eq 0 ]]; then
# check the number of threads running
THREADS_IN_USE=$( ps -Afe | grep wget | grep 'YOURCOMMAND' | wc -l );
# if over the limits, wait to free...
while [[ $THREADS_IN_USE -gt $NUM_MAX_THREADS ]];
do echo "WAITING THREADS TO GET DONE ($THREADS_IN_USE RUNNING)...";
sleep 1;
THREADS_IN_USE=$( ps -Afe | grep wget | grep 'YOURCOMMAND' | wc -l );
done;
# runs the command
{
echo $( YOURCOMMAND "$LINE" ) >> $OUT_FILE;
} &
fi;
# TIP, use my estimate.sh to get the remaining time.
# get the process average per second.
NUM_LINES_DONE=$(cat $OUT_FILE | wc -l);
SECONDS=$(date "+%s");
if [[ $SECONDS -gt $(( SECONDS_AVG + 10 )) ]]; then
SECONDS_ACTUAL=$(( SECONDS - SECONDS_AVG ));
NUM_LINES_DONE_MEDIA=$(( NUM_LINES_DONE - NUM_LINES_DONE_ANT ));
NUM_LINES_DONE_ANT=$NUM_LINES_DONE;
SECONDS_AVG=$SECONDS;
MEDIA=$(( NUM_LINES_DONE_MEDIA / SECONDS_ACTUAL ));
NUM_LINES_REMAINING=$(( TOTAL_LINES - NUM_LINES_DONE ));
REMAINING_TIME=$(( NUM_LINES_REMAINING * MEDIA ));
fi;
# echoes the status and qtd of active threads
echo "Threads running: ${THREADS_IN_USE}, Lines done: $NUM_LINES_DONE, processing line: $(( CURR_LINE++)), MEDIA: $MEDIA Lines/Second, Remaining time: $REMAINING_TIME SECONDS;";
done;
);
give color to your scripts
Use the below codes in bash using 'echo -e ' to colorize your output.
#!/bin/bash
#
# Description:
#
# Prints a color table of 8bg * 8fg * 2 states (regular/bold)
#
# Copyright:
#
# (C) 2009 Wolfgang Frisch <xororand@unfoog.de>
#
# License:
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
echo
echo Table for 16-color terminal escape sequences.
echo Replace ESC with \\033 in bash.
echo
echo "Background | Foreground colors"
echo "---------------------------------------------------------------------"
for((bg=40;bg<=47;bg++)); do
for((bold=0;bold<=1;bold++)) do
echo -en "\033[0m"" ESC[${bg}m | "
for((fg=30;fg<=37;fg++)); do
if [ $bold == "0" ]; then
echo -en "\033[${bg}m\033[${fg}m [${fg}m "
else
echo -en "\033[${bg}m\033[1;${fg}m [1;${fg}m"
fi
done
echo -e "\033[0m"
done
echo "--------------------------------------------------------------------- "
done
echo
echo
estimate.sh
A cool script whoted by myself to calculate the remaining time to a file achieve a number of lines.
devtools:/srv/scripts # cat estimate.sh
#!/bin/bash
# estimate the remaining time for a file to achieve a number
# of lines
# usage
# <scriptName> <fileName> <totaloflines>
file="$1";
vmax=$2;
tini=$(date +%s);
vini=$(cat $file | wc -l);
while ( sleep 1 );
do
# get the current number of rows
vact=$(cat $file | wc -l);
# get the rows recovered since the start of script
vela=$((vact-vini));
# get the current time in seconds
tact=$(date +%s);
# get the time elapsed in seconds since the start of script
tela=$((tact-tini));
# discover the average of rows added per second
if (( $tela > 0 )); then
vave=$((vela / tela));
fi;
# get rows remaining
vrem=$(( vmax - vact ))
# get the estimated remaining time
if (( $vave > 0 )); then
trem=$(( vrem / vave ))
fi;
hr=$((trem / 3600 ))
mr=$((trem / 60 % 60 ))
sr=$((trem % 60 ))
echo "Linhas processadas: $vact; linhas restantes: $vrem; tempo restante: $hr:$mr:$sr;";
done;
gnu bash script template
If you want to do a nice script in gnu way you may think useful:
#
# A sample program illustrating shell option parsing.
#
# Copyright (C) 2007 by Bob Proulx <[EMAIL PROTECTED]>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
version=0.0
progname=$(basename $0)
print_help()
{
cat <<'EOF'
Usage: exampleprog [options] SOURCE...
or: exampleprog [options] DIRECTORY
Do something with something. Write your man page description here.
Options:
--help print this help message
--version print program version
-a, --alpha do alpa
-b, --bravo=STRING do bravo
-d, --debug debug program
-q, --quiet quiet output
-v, --verbose verbose output
Examples:
The most common use is to run it like this.
$ exampleprog
But sometimes like this.
$ exampleprog -q -a --bravo=foo
Report bugs to.
EOF
}
print_version()
{
cat <.
There is NO WARRANTY, to the extent permitted by law.
Written by Bob Proulx.
EOF
}
SHORTOPTS="ab:dqv"
LONGOPTS="help,version,alpha,bravo:,debug,quiet,verbose"
if $(getopt -T >/dev/null 2>&1) ; [ $? = 4 ] ; then # New longopts getopt.
OPTS=$(getopt -o $SHORTOPTS --long $LONGOPTS -n "$progname" -- "$@")
else # Old classic getopt.
# Special handling for --help and --version on old getopt.
case $1 in --help) print_help ; exit 0 ;; esac
case $1 in --version) print_version ; exit 0 ;; esac
OPTS=$(getopt $SHORTOPTS "$@")
fi
if [ $? -ne 0 ]; then
echo "'$progname --help' for more information" 1>&2
exit 1
fi
eval set -- "$OPTS"
alpha=false
bravo=""
debug=false
quiet=false
verbose=false
while [ $# -gt 0 ]; do
: debug: $1
case $1 in
--help)
print_help
exit 0
;;
--version)
print_version
exit 0
;;
-a|--alpha)
alpha=true
shift
;;
-b|--bravo)
bravo=$2
shift 2
;;
-d|--debug)
debug=true
shift
;;
-q|--quiet)
quiet=true
shift
;;
-v|--verbose)
verbose=true
shift
;;
--)
shift
break
;;
*)
echo "Internal Error: option processing error: $1" 1>&2
exit 1
;;
esac
done
if $verbose; then
echo "Verbose output here."
fi
if ! $quiet; then
echo Say stuff here.
fi
$debug && echo No bugs found here.
exit 0
segunda-feira, 2 de maio de 2011
Oracle 10g ugly index/trigger bug
today, I found a ugly bug in oracle 10g:
In database log:
If you drop the index or disable the trigger or do not use the timestamp field in update, everythings is alright...
I has received it in 5 different oracle databases but all in version 10.2.0.4
The way we founded was create a index by the full field timestamp, not using trunc();
All things works ok... I know... it's not the best option, but a workaround...
Remember:
no more for now...
CREATE TABLE TABLE_TESTBUG (
ID_REG NUMBER NOT NULL PRIMARY KEY,
DT_FIELD1 TIMESTAMP(6),
STATUS NUMBER(10)
);
CREATE OR REPLACE TRIGGER TG_TESTBUG
after INSERT OR UPDATE ON TABLE_TESTBUG
FOR EACH ROW
DECLARE
V_VAR NUMBER;
BEGIN
SELECT COUNT(*) INTO V_VAR
FROM DUAL
WHERE TRUNC(SYSDATE)=TRUNC(:new.DT_FIELD1);
END;
/
SQL> INSERT INTO TABLE_TESTBUG (ID_REG, DT_FIELD1, STATUS) VALUES (1, SYSDATE, 1);
1 row created.
SQL> INSERT INTO TABLE_TESTBUG (ID_REG, DT_FIELD1, STATUS) VALUES (2, SYSDATE, 1);
1 row created.
SQL> INSERT INTO TABLE_TESTBUG (ID_REG, DT_FIELD1, STATUS) VALUES (3, SYSDATE-1, 1);
1 row created.
SQL> CREATE INDEX IDX_TESTBUG_1 ON TABLE_TESTBUG (TRUNC(DT_FIELD1),STATUS);
Index created.
SQL> UPDATE TABLE_TESTBUG SET STATUS=3 WHERE TRUNC(DT_FIELD1)=TRUNC(SYSDATE);
UPDATE TABLE_TESTBUG SET STATUS=3 WHERE TRUNC(DT_FIELD1)=TRUNC(SYSDATE)
*
ERROR at line 1:
ORA-03113: end-of-file on communication channel
Process ID: 0
Session ID: 3284 Serial number: 2922
In database log:
Errors in file /opt/oracle/admin/*****/udump/*****_ora_24645.trc:
ORA-07445: exception encountered: core dump [_intel_fast_memcpy.A()+10] [SIGSEGV] [Invalid permissions for mapped object] [0x2AE125E59000] [] []
If you drop the index or disable the trigger or do not use the timestamp field in update, everythings is alright...
I has received it in 5 different oracle databases but all in version 10.2.0.4
The way we founded was create a index by the full field timestamp, not using trunc();
SQL>drop index idx_testbug_1;
Index dropped.
SQL>create index idx_textbug_1 on table_testbug (dt_field1);
Index created.
All things works ok... I know... it's not the best option, but a workaround...
Remember:
To use index you need to use "between", not "trunc"
no more for now...
Assinar:
Postagens (Atom)
