tag:blogger.com,1999:blog-50455850147793782432024-03-14T07:00:23.577-07:00gulden-ptGulden as a bloggerGulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.comBlogger43125tag:blogger.com,1999:blog-5045585014779378243.post-56306645558430895872017-07-12T05:00:00.001-07:002017-07-12T05:00:59.606-07:00PAINTING BIG RED LIPS!!!!<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/oT7CNQvPo_Y" width="480"></iframe>Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-50648211366069516262017-06-22T02:14:00.001-07:002017-06-22T02:14:31.894-07:00DIY FOAM DOLL! [ PART 2]<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/jfnuj_ZjEkI" width="480"></iframe>Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-12747291485837313002017-02-06T03:30:00.001-08:002017-02-06T03:30:30.974-08:00DIY Foam Doll (part 1)<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/qX2wuw2s9oY" width="480"></iframe>Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-58944998123802329302017-01-09T06:39:00.001-08:002017-01-09T06:40:28.570-08:00BIG MANDALA!<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/vtykpLa8QkI" width="480"></iframe>Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-4817063609435431332016-11-17T09:43:00.001-08:002016-11-17T09:43:17.748-08:00BUTTERFLY WORLD PART 1<iframe width="480" height="270" src="https://www.youtube.com/embed/nk1B4eJae0c" frameborder="0" allowFullScreen=""></iframe>Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-59026312027860859092016-11-11T07:00:00.001-08:002016-11-11T07:01:13.674-08:00MY TRUE GUARDIAN ANGEL<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/u20lPLLPlDE" width="480"></iframe>Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-80436413542373339842016-10-21T16:00:00.001-07:002016-10-21T16:01:40.089-07:00good vs evil part II<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/mcf_QuPsvnU" width="480"></iframe>Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-82978784966079250032016-10-18T07:47:00.001-07:002016-10-18T07:48:21.480-07:00Good vs Evil<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/4cL_wwNpZoU" width="480"></iframe>Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-91309832132919060582016-10-03T14:27:00.001-07:002016-10-03T14:28:10.076-07:00DRAWING A GIRL WHITH A MASSIVE DRESS (PART 1)<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/zV19NPEQkzs" width="480"></iframe>Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-8883849505742786802016-09-21T14:43:00.001-07:002016-09-21T15:04:13.752-07:00How to DRAW an AVATAR!!!<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/lYfZX_a8FHY" width="480"></iframe>Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-8871552102829154052013-01-27T15:31:00.001-08:002013-01-27T15:40:37.294-08:00M101: MongoDB for Developers<br />
I am pleased to announce that I've concluded with distinction the course of MongoDB. My final grade of 95% puts me in the top 5% of all students ( 21,116 in total) who registered for the course.<br />
<br />
You can find other stats on the course on the <a href="http://ed-blog.10gen.com/post/38413879802/m101-completion-stats?mkt_tok=3RkMMJWWfF9wsRohuKzJZKXonjHpfsX97%2BwqWaG%2FlMI%2F0ER3fOvrPUfGjI4HS8tgI%2FqLAzICFpZo2FEJSueQcg%3D%3D">link</a><br />
<br />
And this is my certificate:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRxlZ2UnYo22g6RsCUSBP5cetMkroVd7Q8JffBHPiQ_FOOUNhRkTB7jyQPtFFtlNzoiSRgtuqyTc16gU8GN1eIRAEPlmQcHKDMmR0Lvmbpghq-yM0mbSZa61HteqzQKEeW0lpA5NEg798/s1600/Gulden_MongoDB_Certification.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="271" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRxlZ2UnYo22g6RsCUSBP5cetMkroVd7Q8JffBHPiQ_FOOUNhRkTB7jyQPtFFtlNzoiSRgtuqyTc16gU8GN1eIRAEPlmQcHKDMmR0Lvmbpghq-yM0mbSZa61HteqzQKEeW0lpA5NEg798/s400/Gulden_MongoDB_Certification.png" width="400" /></a></div>
<br />
<br />
If you intend to start with MongoDB <a href="https://education.10gen.com/" target="_blank">this course</a> is the right place to start.Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-88333933363924731142012-10-03T03:56:00.001-07:002012-10-03T04:55:17.034-07:00Before start coding in Node.JSFollowing on the Node.js hype, I've noticed that a lot of people are talking about Node.js but do you really know how it works?<br />
Before start coding in Node.js is necessary to understand how it works internally and understand a new programming paradigm. So, in my talk i'll start talking about the internal architecture of Node.js and which core libraries are being used in windows and linux. It is very important to understand the concept of event driven programming as well as how the event loop works internally and, therefore, prevent the development of bad code or apply Node.js for a function for which it was not designed. The fundamental concepts about Node.js are very simple, but first you have to learn them.<br />
<br />
Finally, I will talk about how to do profiling in Node.js, some performance tips and present some real cases where Node.js is being used.<br />
<br />
Presentation Topics<br />
<br />
<ul>
<li>Internal Architecture</li>
<li>Asynchronous I / O</li>
<li>Event Driven Programming</li>
<li>EventLoop</li>
<li>Node.js is single threaded?</li>
<li>Flow control</li>
<li>Performance tips</li>
<li>WebSockets</li>
<li>Who & How is using Node.js</li>
</ul>
<br />
<script async="async" class="speakerdeck-embed" data-id="506c16702838cc000204e3b1" data-ratio="1.3333333333333333" src="//speakerdeck.com/assets/embed.js"></script>
If you are interested in this talk, please contact me.<span style="font-family: arial, sans-serif; font-size: x-small;"><span style="line-height: 18px;"><br /></span></span>
<span style="font-family: arial, sans-serif; font-size: x-small;"><span style="line-height: 18px;"><br /></span></span>
Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-56785323742366014402012-05-25T10:10:00.000-07:002012-06-05T11:52:28.281-07:00Hash read performance (perl,ruby,python,node.js)<br />
After having read the chapter "How Hashes Scale From One To One Million Elements" from the book "<a href="http://patshaughnessy.net/Ruby-Under-a-Microscope-Rough-Draft-May.pdf" style="background-color: white; border: 0px; font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; font-size: 14px; line-height: 24px; margin: 0px; padding: 0px;">Ruby Under A Microscope</a>" (<i>This post does not dispense the reading of the respective chapter</i>), I decided to play around with the subject and make some tests with other languages and do a small analysis of the performance of each. The chosen languages were <a href="http://www.perl.org/">Perl</a>, <a href="http://www.ruby-lang.org/">Ruby</a>, <a href="http://www.python.org/">Python</a> and Javascript (<a href="http://nodejs.org/">node.js</a>).<br />
<br />
The tests focused on measuring the time in ms when retrieving an element from a hash with N elements 10.000 times and were based on tests that were performed on the book.<br />
<div>
<br /></div>
The tests were run on an Amazon EC2 server instance (free tier) with the following characteristics:<br />
<div>
<ul>
<li>Ubuntu Server 12.04 LTS</li>
<li>Instance type micro</li>
<li>Intel(R) Xeon(R) CPU E5430 @ 2.66GHz</li>
<li>604.364 KB of memory</li>
<li>64-bit platform</li>
</ul>
<div>
<h4>
</h4>
<h2>
Test description</h2>
<div>
Programs have been implemented for each of the languages to be tested and they are similar as long as possible.The implementation passed by the creation of hashes with size equals to powers of 2, ranging from 1 to 20.</div>
<br />
For each of the hashes created, are made 10.000 gets of the value for a key (key=target_index), and measuring the time in milliseconds.<br />
<br />
The measured values are placed in an output file for later to be consumed by a program that will generate the graphics.<br />
<br />
<h2>
Comparing Ruby Versions</h2>
<div>
From the graphs we can see greater improvements from ruby 1.8 to ruby 1.9 so 1.9 is the the way to go.</div>
<div>
<h2 style="text-align: center;">
<img src="http://chart.apis.google.com/chart?chxl=0:|2|4|8|16|32|64|128|256|512|1024|2048|4096|8192|16384|32768|65536|131072|262144|524288|1048576&chxt=x,y&chco=c3238a,e4e659,f33b2c,68cb0d&chf=bg,s,efefef&chd=s:0z110121434592543311,YXaYZXZYZYZZYaYZZZaY,vuvwvvuuwutwvvzvvwxw,YXYYZYXYZZXZYXaZXZaa&chdl=ruby-1.8.7-p358|ruby-1.9.3-p194|ree-1.8.7|ruby-1.9.2-p320&chtt=Hash+Reads+Performance&cht=lc&chs=500x300&chxr=1,0,4.4" />
</h2>
<div style="text-align: center;">
Time taken to retrieve 10.000 values (ms)</div>
<h2>
Comparing Perl Versions</h2>
</div>
<div>
Perl is a language with some years and performance has been stable at least since version 5.8, the results show it.Yet I hoped there were more commitment from the community in trying to optimize these values.</div>
<div>
<h2>
</h2>
<h2 style="text-align: center;">
<img src="http://chart.apis.google.com/chart?chxl=0:|2|4|8|16|32|64|128|256|512|1024|2048|4096|8192|16384|32768|65536|131072|262144|524288|1048576&chxt=x,y&chco=d01239,5d6c21,a4b210&chf=bg,s,efefef&chd=s:5tzusuvszzwzww26xw4z,250w2x43332213y49111,yzxzxzr1uyxz7srwu0rz&chdl=perl-5.8.9|perl-5.16.0|perl-5.14.2&chtt=Hash+Reads+Performance&cht=lc&chs=500x300&chxr=1,0,1.75" />
</h2>
<div style="text-align: center;">
Time taken to retrieve 10.000 values (ms)</div>
<h2>
Comparing Python Versions</h2>
</div>
<div>
The versions of python show few variations and show some stability between versions. However python 3.2.3 shows a slight degradation in performance.<br />
I may also say that it's performance is quite interesting.<br />
<br /></div>
<div style="text-align: center;">
<img src="http://chart.apis.google.com/chart?chxl=0:|2|4|8|16|32|64|128|256|512|1024|2048|4096|8192|16384|32768|65536|131072|262144|524288|1048576&chxt=x,y&chco=b9ce4e,1fcf4f,9f9abe&chf=bg,s,efefef&chd=s:zst0wtzstss4tssr5tw,x343729356543527345,twtxu0t0twtttwvu03v&chdl=python-2.7.3|python-3.2.3|python-2.4.6&chtt=Hash+Reads+Performance&cht=lc&chs=500x300&chxr=1,0,1,0.89" />
</div>
<div style="text-align: center;">
Time taken to retrieve 10.000 values (ms)</div>
<div>
<h2>
Comparing Languages</h2>
</div>
<div>
Represented in the graph below are the tests for all languages and respective versions.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://chart.apis.google.com/chart?chxl=0:|2|4|8|16|32|64|128|256|512|1024|2048|4096|8192|16384|32768|65536|131072|262144|524288|1048576&chxt=x,y&chco=883a81,0c36d0,de7aa8,7d57e3,dffa6a,22a2ec,7b2835,67dfdc,2d732d,10a303,b18a2a&chf=bg,s,efefef&chd=s:WSUSRSSRUUTUTTVXTTWU,0z110121434592543311,KJJKJJKJJJJLJJJILJJ,YXaYZXZYZYZZYaYZZZaY,vuvwvvuuwutwvvzvvwxw,KLLLLKMLLLLLLLKLLLL,VWUTVTWWVWVVVVUWYVVV,YXYYZYXYZZXZYXaZXZaa,AAAAAAAOAAOOAAAOAOOO,UUTUTURVSUTUXRRTSURU,JJJKJKJKJJJJJJJJKLJ&chdl=perl-5.8.9|ruby-1.8.7-p358|python-2.7.3|ruby-1.9.3-p194|ree-1.8.7|python-3.2.3|perl-5.16.0|ruby-1.9.2-p320|node-0.6.18|perl-5.14.2|python-2.4.6&chtt=Hash+Reads+Performance&cht=lc&chs=500x300&chxr=1,0,4.4" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://chart.apis.google.com/chart?chxl=0:|2|4|8|16|32|64|128|256|512|1024|2048|4096|8192|16384|32768|65536|131072|262144|524288|1048576&chxt=x,y&chco=883a81,0c36d0,de7aa8,7d57e3,dffa6a,22a2ec,7b2835,67dfdc,2d732d,10a303,b18a2a&chf=bg,s,efefef&chd=s:WSUSRSSRUUTUTTVXTTWU,0z110121434592543311,KJJKJJKJJJJLJJJILJJ,YXaYZXZYZYZZYaYZZZaY,vuvwvvuuwutwvvzvvwxw,KLLLLKMLLLLLLLKLLLL,VWUTVTWWVWVVVVUWYVVV,YXYYZYXYZZXZYXaZXZaa,AAAAAAAOAAOOAAAOAOOO,UUTUTURVSUTUXRRTSURU,JJJKJKJKJJJJJJJJKLJ&chdl=perl-5.8.9|ruby-1.8.7-p358|python-2.7.3|ruby-1.9.3-p194|ree-1.8.7|python-3.2.3|perl-5.16.0|ruby-1.9.2-p320|node-0.6.18|perl-5.14.2|python-2.4.6&chtt=Hash+Reads+Performance&cht=lc&chs=500x300&chxr=1,0,4.4" /></a></div>
<div style="text-align: center;">
Time taken to retrieve 10.000 values (ms)</div>
<br /></div>
</div>
<div>
<div>
<span style="text-align: center;"><span style="text-align: -webkit-auto;">Python was the winner for the interpreted languages. </span></span>node.js has a great performance however the library used in node.js is not enough accurate to give us reliable values.</div>
<div>
You can easily do the tests in your environment using my scripts, the source code used in this tests can be found on <a href="https://github.com/mgarcia/snippets/tree/master/hash_performance">Github</a>. I've used <a href="https://rvm.io/">rvm</a>, <a href="http://search.cpan.org/~gugod/App-perlbrew-0.42/lib/App/perlbrew.pm">perlbrew</a> and <a href="https://github.com/utahta/pythonbrew">pythonbrew </a>to switch between versions, you can do the same if you want. Nevertheless, you can use your installed versions.</div>
<div>
<br /></div>
<div>
Run the tests:</div>
<div>
<br /></div>
<div>
$ ./experiment1.rb</div>
<div>
$ ./experiment1.pl</div>
<div>
$ ./experiment1.py</div>
<div>
<br /></div>
<div>
The execution of these scripts will create an output file in the form "values.#{lang}-#{version}" (ex: values.perl-5.8.8) for each script.</div>
<div>
<br /></div>
<div>
To generate the graph just run the ruby script (requires gem <a href="https://github.com/mattetti/googlecharts">googlecharts</a>):</div>
<div>
<br /></div>
<div>
$ ./chart.rb</div>
<div>
<br /></div>
<div>
This script will output the link to the googlechart image.</div>
<div>
<br /></div>
In the near future I might do the same but for hash writes and that will be more interesting.</div>
</div>Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com2tag:blogger.com,1999:blog-5045585014779378243.post-24263261133524758462012-04-13T17:04:00.000-07:002012-06-28T10:25:31.526-07:00Count the number of 1'sI've participated in a Quiz where i had to implement a function that counts the number of 1's required to reach a positive integer passed as a parameter.<br />
<br />
Example:<br />
<pre class="ruby" name="code">countOfOnes (12) = 5
1 - one 1
3
4
5
6
7
8
9
10 - two 1's
11 - four 1's
12 - five 1's</pre>
<br />
Since countOfOnes (1) = 1, they have requested to find the next number in which the parameter is equal to the return value of countOfOnes ( countOfOnes(n) = n ).<br />
<div>
<br /></div>
At first glance I've implemented a perl one-liner that returns the number of 1's for an input number. Here it is:<br />
<div>
<br /></div>
<div>
<pre class="ruby" name="code">$ perl -e '$sum += () = /1/g for 1..shift; print "NumberOfOnes=$sum\n"' 111
</pre>
<pre class="ruby" name="code">NumberOfOnes=36
</pre>
<br />
<div>
However, this solution was inefficient due to the high number of invocations needed to find the solution to the quiz.<br />
<br /></div>
<div>
So, analyzing the evolution of the mathematical calculation of the function numOfOnes, I outlined the following recursive algorithm:<br />
<br />
<pre class="ruby" name="code"># NumOfOnes
sub num_of_ones{
my $n = shift;
return 0 if $n < 1;
return 1 if $n <= 9;
my @a = split('',$n);
my $len = length($n);
my $sum = 0;
my $delta = 0;
if($a[0] > 1){
$delta += 10**($len-1);
}else{
$delta += substr($n,1) + 1;
}
$sum += $delta + $a[0]*num_of_ones(9x($len-1))+ num_of_ones(substr($n,1));
return $sum;
}
</pre>
<br />
<br />
Since, recursive functions were used, which were invoked repeatedly with the same parameters, I used the <a href="http://search.cpan.org/~mjd/Memoize-1.01/Memoize.pm" target="_blank">Memoize </a>module, which makes caching for functions with the same parameters.<br />
<br />
Although the previous function is more efficient for calculating the numberOfOnes just for a single number, it is not when you want to go all the way incrementing to find the next number that satisfies the requested condition. Once we have the numOfOnes for the previous number, we only need to count the numOfOnes that exists in the current number and increment numOfOnes of the previous number.
<br />
<br />
The following perl on-liner is a better approach to achieve that<br />
<br />
<pre class="ruby" name="code">perl -e 'while(1){$sum += () = ++$i =~ /1/g; print "Found:$i\n" if $i == $sum;}'
Found:1
Found:199981
Found:199982
Found:199983
Found:199984
Found:199985
Found:199986
Found:199987
Found:199988
Found:199989
Found:199990
Found:200000
Found:200001
</pre>
<br />
The number after the 1 that satisfies the condition countOfOnes(n) = n is <b>199981</b><br />
<b><br /></b><br />
The source code is <a href="https://github.com/mgarcia/snippets/blob/master/number_of_ones/number_of_ones.pl" target="_blank">here</a>.<br />
<br />
<br /></div>
</div>Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-12602295174373498152011-03-10T05:23:00.000-08:002011-03-10T09:04:41.279-08:00How to collect CPU values from WMI. #perl #win32 #wmiThis program will demonstrate how easy it is to obtain data from Windows Management Instrumentation (<a href="http://en.wikipedia.org/wiki/Windows_Management_Instrumentation">WMI</a>), using a perl script. By analogy other information may be collected from WMI.<br /><br />To obtain these data, I used the WMI Performance Counter class "<a href="http://msdn.microsoft.com/en-us/library/aa394317(v=vs.85).aspx">Win32_PerfRawData_PerfOS_Processor</a>" , which provides me the counters that measure aspects of processor(s) activity.<br /><br />Since the data collected via WMI are percentages. I just needed to calculate the percentage of time used for each counter, depending on the time interval between measurements.<br /><br /><pre name="code" class="ruby"><br /><br />use strict;<br />use warnings;<br /><br />use Win32::OLE;<br /><br /><br />my $interval = 1;<br />my $key = 'Name';<br />my @properties = qw(PercentIdleTime PercentProcessorTime PercentPrivilegedTime PercentUserTime PercentInterruptTime TimeStamp_Sys100NS);<br /><br />my $hash1 = {};<br /><br />my $wmi = Win32::OLE->GetObject("winmgmts://./root/cimv2")<br /> or die "Failed to get object\n";<br /><br /><br />my $list = $wmi->InstancesOf('Win32_PerfRawData_PerfOS_Processor')<br /> or die "Failed to get instance object\n";<br /><br />my $v; <br />foreach $v (in $list) { <br /> map{$hash1->{$v->{$key}}->{$_} = $v->{$_} }@properties;<br />}<br /> <br />while(sleep 1){<br /><br /> $list = $wmi->InstancesOf('Win32_PerfRawData_PerfOS_Processor')<br /> or die "Failed to get instance object\n";<br /> <br /> my $hash = {};<br /> foreach $v (in $list) { <br /> map{$hash->{$v->{$key}}->{$_} = $v->{$_} }@properties;<br /> }<br /><br /> my $cpu_time = sprintf("%.2f", (1 - get_value($hash1->{'_Total'}, $hash->{'_Total'}, 'PercentProcessorTime' )) * 100);<br /> my $cpu_idle = sprintf("%.2f", 100-$cpu_time);<br /> my $cpu_user = sprintf("%.2f", get_value($hash1->{'_Total'}, $hash->{'_Total'}, 'PercentUserTime' )* 100);<br /> my $cpu_priv = sprintf("%.2f", get_value($hash1->{'_Total'}, $hash->{'_Total'}, 'PercentPrivilegedTime' )* 100);<br /> my $cpu_int = sprintf("%.2f", get_value($hash1->{'_Total'}, $hash->{'_Total'}, 'PercentInterruptTime' )* 100); <br /> printf "CPU Time %s %% , privileged %s %% , user %s %%, interrupt %s %%\n", $cpu_time,$cpu_priv,$cpu_user,$cpu_int;<br /><br /> $hash1 = $hash;<br />}<br /><br /><br />exit;<br /><br />sub get_value {<br /> my $h1 = shift;<br /> my $h2 = shift;<br /> my $property = shift;<br /> return (($h2->{$property} - $h1->{$property})/($h2->{'TimeStamp_Sys100NS'}-$h1->{'TimeStamp_Sys100NS'}));<br />}<br /><br /></pre><br /><br /><br />Output sample:<br /><br /><pre name="code" class="ruby"><br />CPU Time 2.03 % , privileged 1.96 % , user 0.00 %, interrupt 0.00 %<br />CPU Time 1.87 % , privileged 1.96 % , user 0.00 %, interrupt 0.00 %<br />CPU Time 2.16 % , privileged 1.96 % , user 0.00 %, interrupt 0.00 %<br />CPU Time 1.76 % , privileged 1.96 % , user 0.00 %, interrupt 0.00 %<br />CPU Time 2.19 % , privileged 1.96 % , user 0.00 %, interrupt 0.00 %<br />CPU Time 1.77 % , privileged 1.96 % , user 0.00 %, interrupt 0.00 %<br />CPU Time 1.98 % , privileged 1.96 % , user 0.00 %, interrupt 0.00 %<br />CPU Time 1.93 % , privileged 1.96 % , user 0.00 %, interrupt 0.00 %<br />CPU Time 2.08 % , privileged 1.96 % , user 0.00 %, interrupt 0.00 %<br />CPU Time 2.84 % , privileged 2.94 % , user 0.00 %, interrupt 0.00 %<br /></pre>Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-38125664953797512212010-09-08T10:23:00.000-07:002010-09-10T22:05:17.558-07:00Diff between two files (unordered and with different number of lines)This program will find the differences between two files, and should be applied in the following situations:<br /><ul> <li>The files have different number of lines</li> <li>The files are unordered.</li><li>`diff` fails to get the differences</li><li>Large files (the reason to use shell `sort` function)</li><li>Single record per line</li></ul>For example: Imagine you have two files with a list of users, and these listings were taken from a database at different time instants. These listings will be different because users have been added and removed from the database. This script will help you to find the differences when `diff` can't resolve it.<br /><span class="Apple-style-span"><span class="Apple-style-span" style="font-size: 13px; white-space: pre;"><span class="Apple-style-span"><span class="Apple-style-span" style="font-size: 16px; white-space: normal;"><br /></span></span></span></span><pre name="code" class="ruby">#!/usr/bin/perl -w<br /><br />use strict;<br /><br />my $file1= $ARGV[0];<br />my $file2= $ARGV[1];<br /><br />unless($file1 and $file2){<br />print "Usage: $0 <file1> <file2>\n\n";<br />exit;<br />}<br />unless( -f $file1){<br />print "File 1 does not exist: [$file1]\n\n";<br />exit;<br />}<br />unless( -f $file2){<br />print "File 2 does not exist: [$file2]\n\n";<br />exit;<br />}<br /><br /><br />my $tmp_file1 = '/tmp/f1.tmp';<br />my $tmp_file2 = '/tmp/f2.tmp';<br /><br />`sort $file1 > $tmp_file1`;<br />`sort $file2 > $tmp_file2`;<br /><br />open(F1, $tmp_file1) or die "$!";<br />open(F2, $tmp_file2) or die "$!";<br /><br />my $read_f1 = 1;<br />my $read_f2 = 1;<br /><br />my $s1;<br />my $s2;<br />while(1){<br /><br />if (eof(F1)){print ">>$_" while <F2>;}<br />if(eof(F2)){print "<<$_" while <F1>;}<br /><br />if($read_f1){$s1 = <F1>;}<br />if($read_f2){$s2 = <F2>;}<br /><br />last unless $s1 and $s2;<br /><br />$read_f1 = 1;<br />$read_f2 = 1;<br /><br />next if ( lc($s1) eq lc($s2) );<br /><br />if(lc($s1) gt lc($s2)){<br />print ">$s2";<br />$read_f1 = 0;<br />}else{<br />print "<$s1";<br />$read_f2 = 0;<br />}<br />}<br /><br />unlink $tmp_file1 or die "$!";<br />unlink $tmp_file2 or die "$!";<br /><br /><br /><br /></pre>Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-86833107872649772102010-05-12T09:46:00.000-07:002010-05-12T09:59:18.762-07:00How to kill TCP client connectionsSeveral times we are faced with a large number of TCP connections from the same source IP.<br />How to kill that connections?<br /><br />This is an easy way:<br /><pre name="code" class="ruby"><br />$ for i in `lsof -i tcp@client_ip_address| awk '{print $2}'`; do kill -9 $i; done <br /></pre><br /><br />See also : <i><a href="http://en.wikipedia.org/wiki/Tcpkill">tcpkill</a></i>Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-47483516484756434392009-11-02T06:18:00.000-08:002012-06-28T10:23:57.854-07:00Solaris: analyze a core dump fileWhenever there is a coredump, the task of uncovering the source of the problem may not be easy. In Solaris we have some tools that will give us clues in order to solve the problem.<br />
<br />
Coredump files on Solaris are generated in the directory:<br />
<pre class="ruby" name="code">
/var/core/</pre>
<br />
Once in that directory, find your file core. Then run the following commands:<br />
<pre class="ruby" name="code">
$ pstack <core_filename>
core 'core_host_progname_1001_1_1256228346_13885' of 13885: /opt/coolstack/bin/perl -w /export/home/user/bin/progname
----------------- lwp# 1 / thread# 1 --------------------
fede5d77 lwp_yield (fed32a00) + 7
feddfa66 mutex_unlock (fee5c5d0) + 133
fed846ce malloc (15, 8be8ed0, 8dcf888, 80cf342) + 3e
080c20ac Perl_safesysmalloc () + 2c
----------------- lwp# 2 / thread# 2 --------------------
fede5ceb __lwp_park (87a93c8, 87a9398, 0) + b
fede04f0 cond_wait_queue (87a93c8, 87a9398, 0) + 5e
fede09c4 _cond_wait (87a93c8, 87a9398) + 64
fede0a06 cond_wait (87a93c8, 87a9398) + 21
fede0a3f pthread_cond_wait (87a93c8, 87a9398, 1, fe7a8108) + 1b
fe7a82a8 XS_threads__shared_cond_wait (0, 0, 0, 0, 0, 0) + 1ac
4d580000 ???????? ()
----------------- lwp# 3 / thread# 3 --------------------
feabf697 add_collation (fe71bc28, feaf49b7, 1a, feaf49b7) + 54b
feac939b cs_leave (fe71bca0, fe71bd28, 1a, 0, fe71b0c0, fefd261b) + 83
feada60d my_xml_leave (0, fe71b160, fe71b178, feada92b) + 141
feadac9a my_xml_parse (fe71bca0, 8dee0e8, 4755, 0, 0, 0) + 662
feac9ae7 my_parse_charset_xml (8dee0e8, 4755, feabf14c, 0, feffdd28, 4755) + 77
feabf7d5 my_read_charset_file (fe71bf88, fe71bf00, fe71bf50, feffb818, fe71bf14, fefce6f6) + dd
feac01f2 get_charset_by_csname (8dd0a08, 20, 10, 0) + 16a
feadcbab mysql_init_character_set (8b00598, 8d01a8b, c, 2) + 5f
feaddcb5 mysql_real_connect (8b00598, 8af44a8, 89ab6f8, 89b28a0, 8afa190, cea) + 6cd
fec24031 mysql_dr_connect () + 1add
----------------- lwp# 4 / thread# 4 --------------------
feabf697 add_collation (fe65cc28, feaf49b7, 1a, feaf49b7) + 54b
feac939b cs_leave (fe65cca0, fe65cd28, 1a, 0, feaaed64, feffb104) + 83
feada60d my_xml_leave (0, fe65c160, fe65c178, feada92b) + 141
feadac9a my_xml_parse (fe65cca0, 8df2848, 4755, 0, 0, 0) + 662
feac9ae7 my_parse_charset_xml (8df2848, 4755, feabf14c, 0, fee5c5d0, 4755) + 77
feabf7d5 my_read_charset_file (0, 0, 0, 0, 0, 0) + dd
feac01f2 get_charset_by_csname (8dd0a18, 20, 10, 0) + 16a
feadcbab mysql_init_character_set (8bfd4c0, 8d03a9b, c, 2) + 5f
feaddcb5 mysql_real_connect (8bfd4c0, 8bf1bf8, 8bf2380, 8bf23c8, 8bf2440, cea) + 6cd
fec24031 mysql_dr_connect () + 1add</core_filename></pre>
<br />
The command above shows the last state of the stack for each thread (lwp) of the program.<br />
That isn't enough we need to know in each thread the problem have occurred. There is another command that lets us know that, the "pflags" command.<br />
<pre class="ruby" name="code">
$ pflags <core_filename>
core 'core_host_progname_1001_1_1256228346_13885' of 13885: /opt/coolstack/bin/perl -w /export/home/user/bin/progname
data model = _ILP32 flags = MSACCT|MSFORK
/1: flags = STOPPED yield()
why = PR_SUSPENDED
sigmask = 0xffbff8f7,0x0000fff7
/2: flags = STOPPED lwp_park(0x0,0x0,0x0)
why = PR_SUSPENDED
/3: flags = STOPPED
why = PR_SUSPENDED
lwppend = 0x00000400,0x00000000
/4: flags = 0
sigmask = 0xffffbefc,0x0000ffff cursig = SIGSEGV</core_filename></pre>
<br />
Now we know know that thread 4 have received the SIGNAL "SIGSEGV" (Segmentation Fault).<br />
So, the SIGSEGV was generated in Thread 4 when using a MySQL function "add_collation".<br />
<br />
With that information isn't easy to know the reason of the coredump. Lets use another command, the "pmap".<br />
The "pmap" command display information about the address space of a process, in this case the program that causes the coredump.<br />
<pre class="ruby" name="code">
$ pmap <core_filename>| less
core 'core_host_progname_1001_1_1256228346_13885' of 13885: /opt/coolstack/bin/perl -w /export/home/user/bin/progname
08042000 24K rw--- [ stack ]
08050000 1128K r-x-- /opt/coolstack/bin/perl
08179000 52K rwx-- /opt/coolstack/bin/perl
08186000 12752K rwx-- [ heap ]
FE65A000 20K rw--- [ stack tid=4 ]
FE660000 12K r-x-- /lib/nss_dns.so.1
FE673000 4K rw--- /lib/nss_dns.so.1
FE680000 24K r-x-- /lib/nss_files.so.1
FE696000 4K rw--- /lib/nss_files.so.1
FE6A0000 64K rwx--
FE6C0000 64K rwx--
FE719000 20K rw--- [ stack tid=3 ]
FE75E000 4K rw--- [ stack tid=2 ]
FE760000 64K rw---
FE780000 64K rw---
FE7A0000 44K r-x-- /opt/coolstack/lib/perl5/5.8.8/i86pc-solaris-thread-multi/auto/threads/shared/shared.so
FE7BA000 8K rwx-- /opt/coolstack/lib/perl5/5.8.8/i86pc-solaris-thread-multi/auto/threads/shared/shared.so
FE7C0000 8K r-x-- /opt/coolstack/lib/perl5/5.8.8/i86pc-solaris-thread-multi/auto/Cwd/Cwd.so
FE7D1000 4K rwx-- /opt/coolstack/lib/perl5/5.8.8/i86pc-solaris-thread-multi/auto/Cwd/Cwd.so
FE7E0000 64K rwx--
FE800000 40K r-x-- /usr/sfw/lib/libcrypto_extra.so.0.9.7
FE81A000 4K rw--- /usr/sfw/lib/libcrypto_extra.so.0.9.7
FE820000 36K r-x-- /usr/sfw/lib/libssl_extra.so.0.9.7
FE839000 4K rw--- /usr/sfw/lib/libssl_extra.so.0.9.7
FE840000 56K r-x-- /lib/libmd.so.1
FE85E000 4K rw--- /lib/libmd.so.1
FE860000 28K r-x-- /lib/libaio.so.1
FE877000 4K rw--- /lib/libaio.so.1
FE878000 4K rw--- /lib/libaio.so.1
FE880000 936K r-x-- /usr/sfw/lib/libcrypto.so.0.9.7
FE97A000 84K rw--- /usr/sfw/lib/libcrypto.so.0.9.7
FE98F000 8K rw--- /usr/sfw/lib/libcrypto.so.0.9.7
FE9A0000 200K r-x-- /usr/sfw/lib/libssl.so.0.9.7
FE9E2000 12K rw--- /usr/sfw/lib/libssl.so.0.9.7
FE9F0000 24K r-x-- /lib/libgen.so.1
FEA06000 4K rw--- /lib/libgen.so.1
FEA10000 216K r-x-- /lib/libresolv.so.2
FEA56000 8K rw--- /lib/libresolv.so.2
FEA60000 24K r-x-- /lib/librt.so.1
FEA76000 4K rw--- /lib/librt.so.1
FE878000 4K rw--- /lib/libaio.so.1
FE880000 936K r-x-- /usr/sfw/lib/libcrypto.so.0.9.7
FE97A000 84K rw--- /usr/sfw/lib/libcrypto.so.0.9.7
FE98F000 8K rw--- /usr/sfw/lib/libcrypto.so.0.9.7
FE9A0000 200K r-x-- /usr/sfw/lib/libssl.so.0.9.7
FE9E2000 12K rw--- /usr/sfw/lib/libssl.so.0.9.7
FE9F0000 24K r-x-- /lib/libgen.so.1
FEA06000 4K rw--- /lib/libgen.so.1
FEA10000 216K r-x-- /lib/libresolv.so.2
FEA56000 8K rw--- /lib/libresolv.so.2
FEA60000 24K r-x-- /lib/librt.so.1
FEA76000 4K rw--- /lib/librt.so.1
FEA80000 60K r-x-- /usr/lib/libz.so.1
FEA9E000 4K rwx-- /usr/lib/libz.so.1
FEAA0000 352K r-x-- /opt/coolstack/mysql_32bit/lib/mysql/libmysqlclient.so.16.0.0
FEB00000 4K rwx--
FEB07000 1040K rwx-- /opt/coolstack/mysql_32bit/lib/mysql/libmysqlclient.so.16.0.0
FEC0B000 4K rwx-- /opt/coolstack/mysql_32bit/lib/mysql/libmysqlclient.so.16.0.0</core_filename></pre>
<br />
Since the problem occurred in the invocation of a MySQL function, with the "pmap" command, I've detected that my Perl used a DBD:: mysql library which was linked with a 32-bit MySQL library. My OS is 64 bits, however that is not a problem since 32 Bits libmysqlclient_32_bits is compatible with 64 bits MySQL DB's.<br />
Despite all efforts to detect the problem in the program that I was developing, it was found that the problem was in the instance of a 64 bits MySQL DB that was using 32 bits libraries.Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com1tag:blogger.com,1999:blog-5045585014779378243.post-70144428316254385522009-10-29T08:43:00.000-07:002012-06-28T10:22:54.348-07:00QMAIL + detect SMTP Attacks from the same IPA simple way to detect SMTP attacks from a single source IP can be achieved using the following command:<br />
<pre class="ruby" name="code">$ fgrep "tcpserver: pid" "/var/log/qmail/smtp/current" | awk {'print $6'}| sort | uniq -c| sort -rn |less</pre>
<br />
<br />
The output will be similar to:<br />
<br />
<pre class="ruby" name="code"> 59 72.15.222.65
42 63.251.135.109
38 66.211.168.231
33 63.251.135.115
29 63.251.135.74
25 213.63.26.144
25 194.65.138.99
23 63.251.135.75
16 194.65.5.228
15 93.102.93.77
15 195.23.124.22
13 212.55.154.23
12 213.91.163.191
12 212.55.154.24
11 212.55.154.21
11 198.31.62.64
10 208.65.131.106
9 98.244.216.176
9 85.243.160.139
...</pre>
<br />
The first column shows the number of tcp connections that have been established and the second column the source IP. If the number of messages from those sources are high and suspicious then you need to block those sources.Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-17448299853445746762009-09-21T03:59:00.000-07:002009-09-21T04:26:02.601-07:00How to recover a corrupted gzip file.Sometimes we are faced with a corrupted ".gz" file, with important information and we must recover it at any cost. Fortunately there is a tool able to recover these files in an efficient manner, the <a href="http://www.urbanophile.com/arenn/coding/gzrt/gzrt.html">gzip Recovery Toolkit</a>.<br /><br />The installation process is very easy:<br /><br />$ wget http://www.urbanophile.com/arenn/coding/gzrt/gzrt-0.5.tar.gz<br />$ tar -xzvf gzrt-0.5.tar.gz<br />$ cd gzrt-0.5<br />$ make<br /><br />And that's it.<br /><br />To start using it just do:<br /><br />$ ./gzrecover file_to_recover.gz<br /><br />then it will create a new filename called "file_to_recover.recovered"<br /><br />You must also read the "<span style="font-weight: bold;">Disclaimer and Warnings</span>"<br /><br /><span style="font-style: italic;">«This program is provided AS IS with absolutely NO WARRANTY. It is not guaranteed to recover anything from your file, nor is what it does recover guaranteed to be good data. The bigger your file, the more likely that something will be extracted from it. Also keep in mind that this program gets faked out and is likely to "recover" some bad data. <span style="font-weight: bold;">Everything should be manually verified</span>. </span>»Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com3tag:blogger.com,1999:blog-5045585014779378243.post-34229427084899205552009-06-11T05:54:00.000-07:002009-06-11T06:04:27.533-07:00Abimago - Image Bank<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.abimago.com"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 286px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6-UGWcUix_hvMyaWkwUC8vSP-n9FlikJI-5IwHToV43M9J7O0VvRFzDw25BKbChUEMY-tpnyG9lGkDNhx9PugSazxuVBViP2Sk0D2u2kSpxJ9I2g_n5unZvCVa4l9hFXCTVjQzaEwww0/s320/Abimago.jpg" alt="" id="BLOGGER_PHOTO_ID_5346053278691115554" border="0" /></a><br /><a href="http://www.abimago.com/">Abimago</a> is a versatile Image Bank, although especially aimed at responding to detailed and specific demands from expert professionals in areas such as advertising, marketing or press.Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-38094279870753701872009-04-09T20:42:00.000-07:002009-04-09T20:54:37.095-07:00HOWTO : SVN over HTTPSCreate the repository<br /><pre name="code" class="ruby"><br />$ svnadmin create /home/svn/repo/svn<br /></pre><br />Install RPM mod_dav_svn<br /><pre name="code" class="ruby"><br />$ yum install mod_dav_svn<br /></pre><br />Config who can access the repository and their permissions (r or w) /home/svn/conf/users-access-file<br /><pre name="code" class="ruby"><br />[/]<br />gulden = rw<br />other = r<br />[/privaterepo]<br />*=<br /></pre><br /><ul><li>"<span style="font-weight: bold;">gulden</span>" user can access the the "/" repository with read and wright (rw) permissions</li><li>"<span style="font-weight: bold;">other</span>" can access the the "/" repository with read (r) permission</li><li><span style="font-weight: bold;">No one</span> can access the "/privaterepo" repository</li></ul><br />Create the Users password file<br /><pre name="code" class="ruby"><br />$ htpasswd /home/svn/conf/passwd gulden<br /></pre><br />Edit Apache configuration file: /etc/httpd/conf.d/subversion.conf<br /><pre name="code" class="ruby"><br />LoadModule dav_svn_module modules/mod_dav_svn.so<br />LoadModule authz_svn_module modules/mod_authz_svn.so<br /><br /><virtualhost 443=""><br />ServerName myhost.com<br />ServerAlias svn.myhost.com<br /><location><br /> Order allow,deny<br /> Allow from all<br /> DAV svn<br /> SVNParentPath /home/svn/repo<br /> # our access control policy<br /> AuthzSVNAccessFile /home/svn/conf/users-access-file<br /> # try anonymous access first, resort to real<br /> # authentication if necessary.<br /> Satisfy Any<br /> Require valid-user<br /> # how to authenticate a user<br /> AuthType Basic<br /> AuthName "My Subversion repository"<br /> AuthUserFile /home/svn/conf/passwd<br /></location><br /></virtualhost><br /><br /></pre><br />Checkout a project<br /><pre name="code" class="ruby"><br /> $ svn co https://svn.myhost.com/svn/foo/trunk<br /></pre>Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-69097228692052536772009-03-09T15:52:00.000-07:002009-03-09T15:59:37.371-07:00HOW TO syntax highlight blogger : widgetFor those who need syntax highlight in their blog, to several programming languages, can use the widget "<a href="http://fazibear.googlepages.com/blogger.html">Blogger Widget SyntaxHighlighter</a>" and is powered by <a href="http://code.google.com/p/syntaxhighlighter/">SyntaxHighlighter 1.5.1</a><br />Give it a try.Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-88115326238531911512009-03-07T19:15:00.000-08:002009-03-09T15:46:13.257-07:00Rails: Where to put our initialization stuffIn our applications we sometimes need to initialize global vars or rails predefined values. Whenever we want to do that, we just need to create files in the directory<br /><pre name="code" class="ruby"><br />config/initializers/<br /></pre><br />instead of messing with the environment.rb file.<br /><br />Source:<a href="http://ryandaigle.com/articles/2007/2/23/what-s-new-in-edge-rails-stop-littering-your-evnrionment-rb-with-custom-initializations"> Ryan's Scraps: What's New in Edge Rails: Stop Littering In Your Environment File</a>Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0tag:blogger.com,1999:blog-5045585014779378243.post-61820706031633659022009-02-23T09:03:00.000-08:002009-02-23T09:07:23.905-08:00Top 10 best and worst of MWC 2009 - vnunet.com<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.mobileworldcongress.com/images/mwc_logo2.gif"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 98px;" src="http://www.mobileworldcongress.com/images/mwc_logo2.gif" alt="" border="0" /></a><br /><br /><a href="http://www.vnunet.com/vnunet/news/2236937/top-ten-best-worst-mwc-2009?page=5">Top 10 best and worst of MWC 2009 - vnunet.com</a>: "Top 10 best and worst of MWC 2009"Gulden PThttp://www.blogger.com/profile/18144846983097902841noreply@blogger.com0