Thursday, March 24, 2016
Thursday, December 31, 2015
Aquecimento global....AHHHHHHHHHHHHHHHHHHHH! VAMOS TODOS MORRER!
Quantas vezes ja ouviram ou disseram coisas como "nunca tivemos um inverno tao quente" ou "o tempo esta todo marado"?
Olhem para isto:
A temperatura media em Portugal aumentou 0.7 graus em 44 anos.
Ja em relacao ao "aquecimento global" (que agora ja chamam "alteracoes climatericas"):
Existiram 24 dias de ondas de calor (dias com temperaturas maxiamas acima do normal) em 1974, e 8 em 2014.
Ja em relacao aos dias sem chuva (em media):
- 178 em 2014
- 225 em 1970
...no entanto, vejam a tabela nessa pagina e vao reparar como este valor sobe e desce ao longo dos anos :o)
E, ja agora, a temperatura máxima do ar no mês mais quente do ano (média mensal):
E, por fim, a temperatura mínima do ar (média anual):
Realmente, ha razao para alarme...esta tudo do avesso :o).
E necessario tomarmos accao de imediato!
Olhem para isto:
A temperatura media em Portugal aumentou 0.7 graus em 44 anos.
Ja em relacao ao "aquecimento global" (que agora ja chamam "alteracoes climatericas"):
Existiram 24 dias de ondas de calor (dias com temperaturas maxiamas acima do normal) em 1974, e 8 em 2014.
Ja em relacao aos dias sem chuva (em media):
- 178 em 2014
- 225 em 1970
...no entanto, vejam a tabela nessa pagina e vao reparar como este valor sobe e desce ao longo dos anos :o)
E, ja agora, a temperatura máxima do ar no mês mais quente do ano (média mensal):
E necessario tomarmos accao de imediato!
Wednesday, September 2, 2015
How to access a django python rest service that uses a login page for authentication
Today we bumped into a little challenge at work where we had to document a REST API in the portal we're developing.
The main problem was that this REST API did not authenticate with http auth. Instead, it relied on authenticating against the portal's (html based) login page, getting the cookie and consuming the REST API from there.
Here's how we solved the problem:
step 1- check the login page's html to see what the username and password form fields are called
(in our case, they were called uName and pwd)
step2- customize the following bash script with your username, password and form fields
The main problem was that this REST API did not authenticate with http auth. Instead, it relied on authenticating against the portal's (html based) login page, getting the cookie and consuming the REST API from there.
Here's how we solved the problem:
step 1- check the login page's html to see what the username and password form fields are called
(in our case, they were called uName and pwd)
step2- customize the following bash script with your username, password and form fields
[root@userportal ~]# cat templates.sh
LOGIN_URL=http://localhost:8081/login/
YOUR_USER='username'
YOUR_PASS='password'
COOKIES=cookies.txt
CURL_BIN="curl -s -c $COOKIES -b $COOKIES -e $LOGIN_URL"
echo "Django Auth: get csrftoken ..."
$CURL_BIN $LOGIN_URL > /dev/null
DJANGO_TOKEN="csrfmiddlewaretoken=$(grep cid $COOKIES | sed 's/^.*cid\s*//')"
echo "DJANGO TOKEN is $DJANGO_TOKEN"
echo "######################################################"
echo "Performing login..."
$CURL_BIN \
-d "$DJANGO_TOKEN&uName=$YOUR_USER&pwd=$YOUR_PASS" \
-X POST $LOGIN_URL
echo "######################################################"
echo "Getting all templates..."
$CURL_BIN \
-d "$DJANGO_TOKEN&..." \
-X GET http://localhost:8081/api/templates/ | python -m json.tool
rm $COOKIES
[root@userportal ~]#
What this script basically does is:
- it connects to the login page and saves its cookies into cookies.txt
- then it reads that file and extracts cookie "cid" to get the value of the "csrfmiddlewaretoken"
- and authenticates against the login page passing your username, password and the csrfmiddlewaretoken variables
At this point you'll be authenticated and the session will be saved in cookies.txt so all there's left to do is call out your REST web service! :o)
Hope this can be of help to someone else!
Tuesday, July 14, 2015
CRIU, a project to implement checkpoint/restore functionality for Linux in userspace
Just bumped into this really cool project called CRIU.
Basically, CRIU lets you checkpoint / restore processes in Linux (from the userspace).
"Checkpoint/Restore In Userspace, or CRIU (pronounced kree-oo, IPA: /krɪʊ/, Russian: криу), is a software tool for Linux operating system. Using this tool, you can freeze a running application (or part of it) and checkpoint it to a hard drive as a collection of files. You can then use the files to restore and run the application from the point it was frozen at. The distinctive feature of the CRIU project is that it is mainly implemented in user space."
I did a small test with a perl application and it worked like a charm. Here's what I did:
Basically, CRIU lets you checkpoint / restore processes in Linux (from the userspace).
"Checkpoint/Restore In Userspace, or CRIU (pronounced kree-oo, IPA: /krɪʊ/, Russian: криу), is a software tool for Linux operating system. Using this tool, you can freeze a running application (or part of it) and checkpoint it to a hard drive as a collection of files. You can then use the files to restore and run the application from the point it was frozen at. The distinctive feature of the CRIU project is that it is mainly implemented in user space."
I did a small test with a perl application and it worked like a charm. Here's what I did:
Step 1- run a test perl script that writes to a temporary file every second
root@docker:~/docker_tests# cat test.pl
#!/usr/bin/perl
use IO::Handle;
my $filename = '/tmp/report.txt';
open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
for (my $i=1; $i <= 300; $i++) {
print $fh "i is $i\n";
$fh->flush();
sleep 1;
}
close $fh;
root@docker:~/docker_tests# ./test.pl &
[1] 14969
root@docker:~/docker_tests# tail /tmp/report.txt
i is 1
i is 2
i is 3
i is 4
i is 5
i is 6
i is 7
root@docker:~/docker_tests#
Step 2 - checkpoint the process id (14969) to a folder called "checkpoint"
root@docker:~/docker_tests# mkdir checkpoint
root@docker:~/docker_tests# criu-1.6/criu dump --shell-job -D checkpoint -t 14969
Warn (arch/x86/crtools.c:132): Will restore 14969 with interrupted system call
root@docker:~/docker_tests#
[1]+ Killed ./test.pl
root@docker:~/docker_tests# ls -l checkpoint/
total 1416
-rw-r--r-- 1 root root 561 Jul 14 16:53 cgroup.img
-rw-r--r-- 1 root root 822 Jul 14 16:53 core-14969.img
-rw-r--r-- 1 root root 60 Jul 14 16:53 creds-14969.img
-rw-r--r-- 1 root root 56 Jul 14 16:53 fdinfo-2.img
-rw-r--r-- 1 root root 18 Jul 14 16:53 fs-14969.img
-rw-r--r-- 1 root root 32 Jul 14 16:53 ids-14969.img
-rw-r--r-- 1 root root 38 Jul 14 16:53 inventory.img
-rw-r--r-- 1 root root 1717 Jul 14 16:53 mm-14969.img
-rw-r--r-- 1 root root 241 Jul 14 16:53 pagemap-14969.img
-rw-r--r-- 1 root root 1388544 Jul 14 16:53 pages-1.img
-rw-r--r-- 1 root root 26 Jul 14 16:53 pstree.img
-rw-r--r-- 1 root root 751 Jul 14 16:53 reg-files.img
-rw-r--r-- 1 root root 794 Jul 14 16:53 sigacts-14969.img
-rw-r--r-- 1 root root 35 Jul 14 16:53 stats-dump
-rw-r--r-- 1 root root 32 Jul 14 16:53 tty.img
-rw-r--r-- 1 root root 169 Jul 14 16:53 tty-info.img
root@docker:~/docker_tests#
Step 3 - verify that the process is no longer running
root@docker:~/docker_tests# ps axuw | grep test.pl
root 14994 0.0 0.0 11748 2208 pts/3 S+ 16:54 0:00 grep --color=auto test.pl
root@docker:~/docker_tests# tail /tmp/report.txt
i is 62
i is 63
i is 64
i is 65
i is 66
i is 67
i is 68
i is 69
i is 70
i is 71
root@docker:~/docker_tests#
Step 4 - restore the process and confirm it picked up exactly where it left off :o)
root@docker:~/docker_tests# criu-1.6/criu restore -d --shell-job -D checkpoint
root@docker:~/docker_tests# ps axuw | grep test.pl
root 14969 0.0 0.0 23548 1348 pts/3 S 16:55 0:00 /usr/bin/perl ./test.pl
root 14974 0.0 0.0 11748 2280 pts/3 S+ 16:56 0:00 grep --color=auto test.pl
root@docker:~/docker_tests# tail /tmp/report.txt
i is 74
i is 75
i is 76
i is 77
i is 78
i is 79
i is 80
i is 81
i is 82
i is 83
root@docker:~/docker_tests#
Sunday, July 12, 2015
ASUS RT-AC68U internal port forwarding issue
Just wanted to share the solution to a problem I was having with my new wifi router (an ASUS RT-AC68U)...
Basically, I have a few port forwarding rules set up and, when I would connect to the external ip address from my internal network, the port forwarding did not work.
I sniffed the network and noticed that the first few packets would be forwarded correctly (between the external ip and the local ip) but, then, the router would start NATing some packets with the router's internal ip address instead of its public one.
Anyway, the fix is pretty easy, you just have to disable NAT Acceleration under NAT \ Switch Control.
Basically, I have a few port forwarding rules set up and, when I would connect to the external ip address from my internal network, the port forwarding did not work.
I sniffed the network and noticed that the first few packets would be forwarded correctly (between the external ip and the local ip) but, then, the router would start NATing some packets with the router's internal ip address instead of its public one.
Anyway, the fix is pretty easy, you just have to disable NAT Acceleration under NAT \ Switch Control.
I hope this information can help someone else :o)
UPDATE: although disabling NAT Acceleration fixed my problem, it caused some heavy performance issues (my home connection dropped from 900Mbps+ to 300Mbps+). Fortunately, I was still able to solve the problem by simply updating to the latest available firmware (3.0.0.4.378_6975-g1f406a7) - they identified this problem as "NAT Loopback problem". The device said I was already using the latest firmware but it turned out that was a lie :oP.
Saturday, July 11, 2015
Five Reasons Why The Greeks Were Right (ou, "a versao da esquerda sobre como a culpa e dos outros")
Five Reasons Why The Greeks Were Right (ou, "a versao da esquerda sobre como a culpa e dos outros")Que artigo mais comuna...
1-"Austerity is not a solution for any economic problem: What creditors and EU bankers and policy makers want is a continuation of the austerity programs that have led to 25% unemployment. Greece said no, and quite right – what economic problem is solved by throwing people out of work? If you were heavily in debt and your bank called you in to discuss your options, can you imagine them recommending that you quit your job?"
- Ah, agora ja percebi. A austeridade de que tanto falam significa despedir pessoas. Fodasse, assim, realmente, nao posso defender a austeridade :o). Eu pensava que austeridade significava "qualidade ou caracteristica do que e austero = RIGOR, SEVERIDADE" ou, por outras palavras, fazer o sector publico gastar so o que pode. La esta, o problema e meu, que estava a usar a definicao do dicionario e nao a definicao da esquerda :o).
2-"From 2001 (the year of Greek entry into the Euro system) through 2007 (the beginning of the world financial crisis), Greece devoted an average of 20.6% of GDP to social programs, while Germany and France were at 26.7% and 28.7%. That’s a significant difference, and in a direction that does not support the lazy-Greek hypothesis."
- ah, pois...o governo Alemao e Frances gastaram mais "programas sociais", LOGO, os gajos nao sao preguicosos. Hmm, e onde esta o custo "escondido" (para o idiota que escreveu o artigo), de ter legislacao que aumenta o salario minimo desproporcionalmente ao valor do que os Gregos produzem, as reformas a partir dos 45 anos, os bonus por "aparecer para trabalhar", etc?
3-"Greek labor productivity has risen faster than German: In fact, not only does Greece spend comparatively less on social programs, but their workers’ productivity rose faster than that of Germans.[...] What the wage repression in Germany meant was that the rising Greek standard of living – one of the goals of joining the euro in the first place – caused a modest Greek trade deficit to grow steadily up through the crisis as German labor costs were suppressed."
- ou seja, a culpa da desgraca Grega e que na Alemanha os SACANAS "suprimiram o custo do trabalho" e os Gregos foram recompensados pelo seu trabalho arduo e productividade, criando esta situacao. La esta, o problema e a Alemanha :o).
4-"The Greek crisis is function of their trade deficit, not government social spending: In order to grasp the true nature of the crisis, it is extremely important to understand that what has happened is a function of Greek trade deficits, not Greek government budget deficits. If Greece buys more goods and services from Germany than Germans buy from Greece, they must finance this by selling financial assets and/or borrowing. This creates external debt. Conversely, if they sell more to the Germans than the Germans buy, then Germany must sell financial assets to or borrow from Greece."
- mas e CLARO, a culpa e da Alemanha, novamente, que exporta mais do que a Grecia. :o)
5-"The Greek crisis is a function of how the Eurozone is organized: The problem facing Europe is a systemic one. Those who try to understand it as being a reflection of individual national characteristics will completely miss the point and any policies that emerge from such an analysis will range from impotent to disastrous (with current recommendations leaning toward the latter). Simply put, the core issue is that the system punishes success."
- Ou seja, os Gregos estao na merda por causa da UE, que penaliza o seu ENORME sucesso ;o(...
1-"Austerity is not a solution for any economic problem: What creditors and EU bankers and policy makers want is a continuation of the austerity programs that have led to 25% unemployment. Greece said no, and quite right – what economic problem is solved by throwing people out of work? If you were heavily in debt and your bank called you in to discuss your options, can you imagine them recommending that you quit your job?"
- Ah, agora ja percebi. A austeridade de que tanto falam significa despedir pessoas. Fodasse, assim, realmente, nao posso defender a austeridade :o). Eu pensava que austeridade significava "qualidade ou caracteristica do que e austero = RIGOR, SEVERIDADE" ou, por outras palavras, fazer o sector publico gastar so o que pode. La esta, o problema e meu, que estava a usar a definicao do dicionario e nao a definicao da esquerda :o).
2-"From 2001 (the year of Greek entry into the Euro system) through 2007 (the beginning of the world financial crisis), Greece devoted an average of 20.6% of GDP to social programs, while Germany and France were at 26.7% and 28.7%. That’s a significant difference, and in a direction that does not support the lazy-Greek hypothesis."
- ah, pois...o governo Alemao e Frances gastaram mais "programas sociais", LOGO, os gajos nao sao preguicosos. Hmm, e onde esta o custo "escondido" (para o idiota que escreveu o artigo), de ter legislacao que aumenta o salario minimo desproporcionalmente ao valor do que os Gregos produzem, as reformas a partir dos 45 anos, os bonus por "aparecer para trabalhar", etc?
3-"Greek labor productivity has risen faster than German: In fact, not only does Greece spend comparatively less on social programs, but their workers’ productivity rose faster than that of Germans.[...] What the wage repression in Germany meant was that the rising Greek standard of living – one of the goals of joining the euro in the first place – caused a modest Greek trade deficit to grow steadily up through the crisis as German labor costs were suppressed."
- ou seja, a culpa da desgraca Grega e que na Alemanha os SACANAS "suprimiram o custo do trabalho" e os Gregos foram recompensados pelo seu trabalho arduo e productividade, criando esta situacao. La esta, o problema e a Alemanha :o).
4-"The Greek crisis is function of their trade deficit, not government social spending: In order to grasp the true nature of the crisis, it is extremely important to understand that what has happened is a function of Greek trade deficits, not Greek government budget deficits. If Greece buys more goods and services from Germany than Germans buy from Greece, they must finance this by selling financial assets and/or borrowing. This creates external debt. Conversely, if they sell more to the Germans than the Germans buy, then Germany must sell financial assets to or borrow from Greece."
- mas e CLARO, a culpa e da Alemanha, novamente, que exporta mais do que a Grecia. :o)
5-"The Greek crisis is a function of how the Eurozone is organized: The problem facing Europe is a systemic one. Those who try to understand it as being a reflection of individual national characteristics will completely miss the point and any policies that emerge from such an analysis will range from impotent to disastrous (with current recommendations leaning toward the latter). Simply put, the core issue is that the system punishes success."
- Ou seja, os Gregos estao na merda por causa da UE, que penaliza o seu ENORME sucesso ;o(...
Subscribe to:
Posts (Atom)


