Ruby https://tech.feedyourhead.at/tags/ruby en Now is a good time to backup our github-repos https://tech.feedyourhead.at/content/now-is-a-good-time-to-backup-our-github-repos <span class="field field--name-title field--type-string field--label-hidden">Now is a good time to backup our github-repos</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Many people are scared because <a href="https://news.microsoft.com/2018/06/04/microsoft-to-acquire-github-for-7-5-billion/">Microsoft bought GitHub</a>. I wonder why people are so shocked now. Github is just another cloud-thingy and cloud means: "it's just the computer of someone else". If "someone else" will shutdown or wipe his computer, then we better have backups. Having this in our minds I would say that it's time to make (auto)backups. I wrote this little ruby-script that clones all public repositories of a user into a directory. If the repositories already exist locally, then this script will just make a "git-pull".</p> <div class="geshifilter"><pre class="ruby geshifilter-ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span> &nbsp; <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'net/http'</span> <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'json'</span> <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'fileutils'</span> &nbsp; directory = <span style="color:#996600;">&quot;./&quot;</span> &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> help warn <span style="color:#996600;">&quot;usage: #{$PROGRAM_NAME} &lt;github-user&gt; [ &lt;dst-directory&gt; ]&quot;</span> <span style="color:#CC0066; font-weight:bold;">exit</span> <span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">end</span> &nbsp; <span style="color:#008000; font-style:italic;"># got this function from stackoverflow.com: </span> <span style="color:#008000; font-style:italic;"># stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby</span> <span style="color:#9966CC; font-weight:bold;">def</span> which<span style="color:#006600; font-weight:bold;">&#40;</span>cmd<span style="color:#006600; font-weight:bold;">&#41;</span> exts = ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'PATHEXT'</span><span style="color:#006600; font-weight:bold;">&#93;</span> ? ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'PATHEXT'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">';'</span><span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#93;</span> ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'PATH'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>::PATH_SEPARATOR<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>path<span style="color:#006600; font-weight:bold;">|</span> exts.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>ext<span style="color:#006600; font-weight:bold;">|</span> exe = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>path, <span style="color:#996600;">&quot;#{cmd}#{ext}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#0000FF; font-weight:bold;">return</span> exe <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">executable</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>exe<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> !<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">directory</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>exe<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">nil</span> <span style="color:#9966CC; font-weight:bold;">end</span> &nbsp; gitbin = which<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;git&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> gitbin.<span style="color:#0000FF; font-weight:bold;">nil</span>? warn <span style="color:#996600;">&quot;git-binary not found&quot;</span> <span style="color:#CC0066; font-weight:bold;">exit</span> <span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">end</span> &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> ARGV.<span style="color:#9900CC;">length</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006666;">1</span> <span style="color:#006600; font-weight:bold;">||</span> ARGV.<span style="color:#9900CC;">length</span> <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">2</span> help <span style="color:#9966CC; font-weight:bold;">end</span> &nbsp; gituser = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> directory = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">if</span> ARGV.<span style="color:#9900CC;">length</span> == <span style="color:#006666;">2</span> &nbsp; <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">directory</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>directory<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#CC00FF; font-weight:bold;">FileUtils</span>::mkdir_p directory <span style="color:#9966CC; font-weight:bold;">end</span> &nbsp; uri = <span style="color:#CC00FF; font-weight:bold;">URI</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;https://api.github.com/users/#{gituser}/repos&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; resp = <span style="color:#6666ff; font-weight:bold;">Net::HTTP</span>.<span style="color:#9900CC;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span>uri<span style="color:#006600; font-weight:bold;">&#41;</span> parsed = JSON.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span>resp<span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; parsed.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span><span style="color:#CC0066; font-weight:bold;">p</span><span style="color:#006600; font-weight:bold;">|</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">directory</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{directory}/#{p['name']}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#CC0066; font-weight:bold;">system</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;cd #{directory}/#{p['name']} &amp;&amp; #{gitbin} pull&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#CC0066; font-weight:bold;">system</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{gitbin} clone https://github.com/#{p['full_name']} #{directory}/#{p['name']}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#9966CC; font-weight:bold;">end</span></pre></div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Jun 07 2018</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/ruby" hreflang="en">Ruby</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/git" hreflang="en">git</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/taxonomy/term/103" hreflang="en">Open-Source</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/backup" hreflang="en">Backup</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/tricks" hreflang="en">Tricks</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/shell" hreflang="en">Shell</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/sysadmin" hreflang="en">Sysadmin</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Linux" hreflang="en">Linux</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=267&amp;2=comment&amp;3=comment" token="oPcbvqzYUcugBxbk0j0w2JLHdMWOfeGFn5WU98XCfbI"></drupal-render-placeholder> </section> Thu, 07 Jun 2018 10:41:24 +0000 Hoti 267 at https://tech.feedyourhead.at cryptorecord 0.9.2 released https://tech.feedyourhead.at/content/cryptorecord-0-9-2-released <span class="field field--name-title field--type-string field--label-hidden">cryptorecord 0.9.2 released</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>I proudly pronounce the first (pre-)release of <a href="https://github.com/whotwagner/cryptorecord">cryptorecord</a>. Cryptorecords is a ruby gem that provides an API and scripts for creating crypto-related dns-records(e.g. DANE). Currently it supports TLSA, OPENPGPKEYS and SSHFP but I plan to support other records in future. The API doesn't create any keys or certificates. It just takes existing keyfiles to create the DNS-records.<br /> &nbsp;</p> <ul> </ul> <h3>Installation</h3> <p>The gem is available on <a href="https://rubygems.org/">Rubygems</a>. Add this line to your application's Gemfile:</p> <pre> <code> gem 'cryptorecord' </code></pre> <p>And then execute:</p> <pre> <code> $ bundle </code></pre> <p>Or install it yourself as:</p> <pre> <code> $ gem install cryptorecord </code></pre> <h3>Usage</h3> <p>This gem comes with a bunch of handy executables that helps creating the dns-records:</p> <ul> <li>openpgpkeysrecord</li> <li>sshfprecord</li> <li>tlsarecord</li> </ul> <pre> <code> Usage: ./openpgpkeysrecord -u <email> -f <gpgkeyfile> -h, --help This help screen -f PGP-PUBLICKEY-FILE, PGP-Publickey-File --publickeyfile -u, --uid EMAIL email-address </gpgkeyfile></email></code></pre> <pre> <code> Usage: ./sshfprecord [ options ] -h, --help This help screen -f SSH-HOST-KEY-FILE, SSH-Hostkey-File --hostkeyfile -H, --host HOST host -d, --digest DIGEST HASH-Algorithm -r, --read-local-hostkeys Read all local Hostkeys.(like ssh-keygen -r) </code></pre> <pre> <code> Usage: ./tlsarecord [ options ] -h, --help This help screen -f, --certfile CERTIFICATE-FILE Certificatefile -H, --host HOST host -p, --port PORTNUMBER port -P, --protocol PROTOCOL protocol(tcp,udp,sctp..) -s, --selector SELECTOR Selector for the association. 0 = Full Cert, 1 = SubjectPublicKeyInfo -u, --usage USAGE Usage for the association. 0 = PKIX-CA, 1 = PKIX-EE, 2 = DANE-TA, 3 = DANE-EE -t, --mtype MTYPE The Matching Type of the association. 0 = Exact Match, 1 = SHA-256, 2 = SHA-512 </code></pre> <h4>TLSA-Example</h4> <pre> <code> #!/usr/bin/env ruby require 'cryptorecord' selector = 0 mtype = 0 usage = 3 port = 443 proto = "tcp" host = "www.example.com" tlsa = Cryptorecord::Tlsa.new(:selector =&gt; selector, :mtype =&gt; mtype, :usage =&gt; usage, :port =&gt; port, :proto =&gt; proto, :host =&gt; host ) tlsa.read_file("/etc/ssl/certs/ssl-cert-snakeoil.pem") puts tlsa </code></pre> <h4>SSHFP-Example</h4> <pre> <code> #!/usr/bin/env ruby require 'cryptorecord' sshfp = Cryptorecord::Sshfp.new(:digest =&gt; 1, :keyfile =&gt; '/etc/ssh/ssh_host_rsa_key.pub', :host =&gt; 'www.example.com') puts sshfp </code></pre> <h4>OPENPGPKEYS-Example</h4> <pre> <code> #!/usr/bin/env ruby require 'cryptorecord' sshfp = Cryptorecord::Openpgpkeys.new(:uid =&gt; "hacky@hacktheplanet.com") sshfp.read_file("resources/hacky.asc") puts sshfp </code></pre> <h3>Documentation</h3> <p>The documentation can be found at <a href="https://www.rubydoc.info/gems/cryptorecord/">rubydoc.info</a></p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">May 17 2018</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/ruby" hreflang="en">Ruby</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/download" hreflang="en">Download</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/downloads" hreflang="en">Downloads</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/security" hreflang="en">Security</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/crypto" hreflang="en">Crypto</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/network" hreflang="en">Network</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=266&amp;2=comment&amp;3=comment" token="8fEI7N9n01EddQ0Ug03YejZAPosvCE9slAcfuGxj-AI"></drupal-render-placeholder> </section> Thu, 17 May 2018 10:13:20 +0000 Hoti 266 at https://tech.feedyourhead.at Suricata Ruby-Gem https://tech.feedyourhead.at/content/suricata-ruby-gem <span class="field field--name-title field--type-string field--label-hidden">Suricata Ruby-Gem</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>I wrote a <a href="https://github.com/whotwagner/suricata">Ruby-Gem</a> for suricata. It offers classes to parse suricata-logs and ships with a nagios-plugin</p> <h2>Installation</h2> <p>Just call:</p> <pre> <code> gem install suricata </code></pre> <h2>Usage</h2> <p>The nagios-plugin searches for specific strings in the description-part of a logfile-entry. It's possible to create a whitelist of search hits which should be excluded.</p> <pre> <code> Usage: check_suricata [ -a alertfile ] [ -w whitelistfile ] -e searchstring -h, --help This help screen -a, --alertfile ALERTFILE alertfile(default: /var/log/suricata/fast.log) -w, --whitelist WHITELISTFILE whitelistfile -e, --search STRING searchstring -i, --interactive interactive -k, --ackfile ACKFILE ackfile(default: /tmp/surack.lst) </code></pre> <p>It is possible to interactively acknowlege search hits so that they will not occur on the next search:</p> <pre> <code> check_suricata -i -e "ET CHAT" Acknowlege the following entry: 10/04/2016-13:39:45.498785 [**] [1:2001595:10] ET CHAT Skype VOIP Checking Version (Startup) [**] [Classification: Potential Corporate Privacy Violation] [Priority: 1] {TCP} 192.168.0.1:40460 -&gt; 15.14.13.12:80 Acknowlege(y|n): y Acknowlege the following entry: 10/05/2016-09:25:01.186862 [**] [1:2001595:10] ET CHAT Skype VOIP Checking Version (Startup) [**] [Classification: Potential Corporate Privacy Violation] [Priority: 1] {TCP} 192.168.0.1:49491 -&gt; 100.254.198.10:80 Acknowlege(y|n): n </code></pre> <h2>Download the Sources</h2> <p>The sources can be found on my <a href="https://github.com/whotwagner/">github-account</a> and can be downloaded using git:</p> <pre> <code> git clone https://github.com/whotwagner/suricata </code></pre> <h2>Future Work</h2> <p>I currently work on a logfile-analyzer for Suricata. It will be included in the furure versions of this gem.</p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Oct 11 2016</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/downloads" hreflang="en">Downloads</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/ruby" hreflang="en">Ruby</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/git" hreflang="en">git</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/taxonomy/term/97" hreflang="en">Toscom</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=209&amp;2=comment&amp;3=comment" token="OxMQl9MNyO5Ozx66YFYnJzt2HiZEoOsLthrf6eJoXdE"></drupal-render-placeholder> </section> Tue, 11 Oct 2016 14:09:28 +0000 Hoti 209 at https://tech.feedyourhead.at HackADay: Controlling computers and stuff with the mind https://tech.feedyourhead.at/content/hack-a-day-controlling-computers-and-stuff-with-my-mind <span class="field field--name-title field--type-string field--label-hidden">HackADay: Controlling computers and stuff with the mind</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>I am very slothful.  I let computers do my work. That's why I became a sysadmin. In this article I am going to describe how I lifted up my lazyness to the next level by triggering a command with my mind to install a new virtual machine with: MariaDB, Nginx and Wordpress.</p> <h2>Intro</h2> <p>When I first read about the <a href="http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0111332">human-to-human-brain-interface</a> I was fascinated. It's like a science-fiction-x-men-story: controlling another human with the mind. But this is a little bit creepy too. Controlling a computer with the mind instead sounds for me more comfortable. In that way I could do all my work just by thinking of it while I am lying in my bed. That's awesome.</p> <h2>Hardware</h2> <p><img alt="Mindwave Equipment" data-entity-type="file" data-entity-uuid="516f6e07-edbb-4697-9daf-652540c07fd7" src="/sites/default/files/inline-images/mindwave_equippment.jpg" /></p> <h3>Headset</h3> <p>I did a little research and it seems the best option for an affordable EEG-headset would be the <a href="http://openbci.com/">OpenBCI-Project</a>. For my proof of concept it is still too expensive, that's why I took the <a href="http://store.neurosky.com/">Neurosky Mindwave Headset</a>. It's has just a few electrodes but it is cheap and might be good enough for my experiment. I ordered a Mindwave-Headset and not a Mindwave-Mobile-headset. The Mindwave-headset ships with a USB-dongle.</p> <p>Neurosky-Devices have a nice feature built-in: <a href="http://developer.neurosky.com/docs/doku.php?id=thinkgear_communications_protocol#thinkgear_data_values">eSense</a>. eSense  calculates the "attention"(are you focused?) and "meditation"(do you have many thoughts?) of a person. I will use this feature for triggering a command-execution.  I could also use the EEG-Data(16bin wave-format), but for this proof-of-concept I am fine with the eSense-meters.</p> <h3>Microcontroller</h3> <p>I have an old Raspberry Pi (Model B) and I installed <a href="https://www.debian.org/releases/jessie/">Debian Jessie</a> on it. A LED on a Gpio-Pin will indicate if I am concentrated or not.</p> <h2>Software</h2> <h3>Reading out EEG-Data</h3> <p>I wrote a <a href="https://github.com/whotwagner/mindwave">ruby gem</a> for interfacing the Mindwave Headset. It simply reads out all the data via serial line and parses it. There are several callback methods to overwrite.  In the following example I will override a method to read out the "attention"-value:</p> <pre> <div class="geshifilter"><pre class="ruby geshifilter-ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>   <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'mindwave'</span>   <span style="color:#9966CC; font-weight:bold;">class</span> EEG <span style="color:#006600; font-weight:bold;">&amp;</span>lt; <span style="color:#6666ff; font-weight:bold;">Mindwave::Headset</span> <span style="color:#008000; font-style:italic;"># override Attention-Callback-Method</span> <span style="color:#9966CC; font-weight:bold;">def</span> attentionCall<span style="color:#006600; font-weight:bold;">(</span>attention<span style="color:#006600; font-weight:bold;">)</span> str = eSenseStr<span style="color:#006600; font-weight:bold;">(</span>attention<span style="color:#006600; font-weight:bold;">)</span> <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">"this is an attention #{attention} #{str}<span style="color:#000099;">\n</span>"</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#9966CC; font-weight:bold;">end</span>   <span style="color:#008000; font-style:italic;"># create a new instance</span> mw = EEG.<span style="color:#9900CC;">new</span> <span style="color:#008000; font-style:italic;"># mw.log.level = Logger::DEBUG</span>   <span style="color:#008000; font-style:italic;"># if we hit ctrl+c then just stop the run()-method</span> <span style="color:#CC00FF; font-weight:bold;">Signal</span>.<span style="color:#CC0066; font-weight:bold;">trap</span><span style="color:#006600; font-weight:bold;">(</span><span style="color:#996600;">"INT"</span><span style="color:#006600; font-weight:bold;">)</span> <span style="color:#9966CC; font-weight:bold;">do</span> mw.<span style="color:#9900CC;">stop</span> <span style="color:#9966CC; font-weight:bold;">end</span>   <span style="color:#008000; font-style:italic;"># Create a new Thread</span> thread = <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">{</span> mw.<span style="color:#9900CC;">run</span> <span style="color:#006600; font-weight:bold;">}</span> <span style="color:#008000; font-style:italic;"># ..and run it</span> thread.<span style="color:#9900CC;">join</span>   mw.<span style="color:#9900CC;">close</span></pre></div></pre> <h3>Manipulating the Raspberry-GPIO-Pins</h3> <p>I found a nice ruby gem for manipulating the GPIO-Pins of my raspberry at <a href="https://rubygems.org/gems/rpi_gpio">rubygems.org.</a> This code will switch the GPIO_Pin 22 on every key-stroke:</p> <pre> <div class="geshifilter"><pre class="ruby geshifilter-ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>   <span style="color:#008000; font-style:italic;"># gem install rpi_gpio</span> <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rpi_gpio'</span> <span style="color:#008000; font-style:italic;"># gem install io-console</span> <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'io/console'</span>   <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">set_numbering</span> <span style="color:#ff3333; font-weight:bold;">:bcm</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">clean_up</span> <span style="color:#006666;">22</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">setup</span> <span style="color:#006666;">22</span>, <span style="color:#ff3333; font-weight:bold;">:as</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#ff3333; font-weight:bold;">:output</span>   GPIO_NUM=<span style="color:#006666;">22</span>   <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">set_high</span> GPIO_NUM   sohigh = <span style="color:#0000FF; font-weight:bold;">true</span>   input = <span style="color:#996600;">'c'</span>   <span style="color:#CC00FF; font-weight:bold;">Signal</span>.<span style="color:#CC0066; font-weight:bold;">trap</span><span style="color:#006600; font-weight:bold;">(</span><span style="color:#996600;">"INT"</span><span style="color:#006600; font-weight:bold;">)</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">"SiGINT Cleaning up.."</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">clean_up</span> GPIO_NUM <span style="color:#CC0066; font-weight:bold;">exit</span> <span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">end</span>     <span style="color:#9966CC; font-weight:bold;">while</span> input != <span style="color:#996600;">"q"</span> input = STDIN.<span style="color:#9900CC;">getch</span>   <span style="color:#9966CC; font-weight:bold;">if</span> sohigh <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">set_low</span> GPIO_NUM <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">set_high</span> GPIO_NUM <span style="color:#9966CC; font-weight:bold;">end</span>   sohigh = !sohigh <span style="color:#9966CC; font-weight:bold;">end</span>   <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">"Cleaning up.."</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">clean_up</span> GPIO_NUM</pre></div></pre> <h2>Controlling a LED</h2> <p>So let's put all parts together. Here is some code which toggles a LED if the attention value is bigger than 79:</p> <pre> <div class="geshifilter"><pre class="ruby geshifilter-ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>   <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'mindwave'</span>   <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rpi_gpio'</span>   <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">set_numbering</span> <span style="color:#ff3333; font-weight:bold;">:bcm</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">clean_up</span> <span style="color:#006666;">22</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">setup</span> <span style="color:#006666;">22</span>, <span style="color:#ff3333; font-weight:bold;">:as</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#ff3333; font-weight:bold;">:output</span>   <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">set_low</span> <span style="color:#006666;">22</span>   <span style="color:#9966CC; font-weight:bold;">class</span> EEG <span style="color:#006600; font-weight:bold;">&amp;</span>lt; <span style="color:#6666ff; font-weight:bold;">Mindwave::Headset</span> <span style="color:#0066ff; font-weight:bold;">@ishigh</span> = <span style="color:#0000FF; font-weight:bold;">false</span> attr_accessor <span style="color:#ff3333; font-weight:bold;">:update</span>     <span style="color:#9966CC; font-weight:bold;">def</span> meditationCall<span style="color:#006600; font-weight:bold;">(</span>meditation<span style="color:#006600; font-weight:bold;">)</span> str = eSenseStr<span style="color:#006600; font-weight:bold;">(</span>meditation<span style="color:#006600; font-weight:bold;">)</span> <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">"Meditation #{meditation} #{str}<span style="color:#000099;">\n</span>"</span> <span style="color:#9966CC; font-weight:bold;">end</span>   <span style="color:#008000; font-style:italic;"># override Attention-Callback-Method</span> <span style="color:#9966CC; font-weight:bold;">def</span> attentionCall<span style="color:#006600; font-weight:bold;">(</span>attention<span style="color:#006600; font-weight:bold;">)</span> str = eSenseStr<span style="color:#006600; font-weight:bold;">(</span>attention<span style="color:#006600; font-weight:bold;">)</span> <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">"-&amp;gt; Attention #{attention} #{str}<span style="color:#000099;">\n</span>"</span>   <span style="color:#9966CC; font-weight:bold;">if</span> attention <span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006666;">79</span> <span style="color:#9966CC; font-weight:bold;">and</span> <span style="color:#0066ff; font-weight:bold;">@update</span> == <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">"FIRE IT UP"</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@ishigh</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">set_low</span> <span style="color:#006666;">22</span> <span style="color:#0066ff; font-weight:bold;">@ishigh</span> = <span style="color:#0000FF; font-weight:bold;">false</span> <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">set_high</span> <span style="color:#006666;">22</span>   <span style="color:#0066ff; font-weight:bold;">@ishigh</span> = <span style="color:#0000FF; font-weight:bold;">true</span> stop <span style="color:#9966CC; font-weight:bold;">end</span>   <span style="color:#0066ff; font-weight:bold;">@update</span> = <span style="color:#0000FF; font-weight:bold;">false</span>   <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#9966CC; font-weight:bold;">end</span>   <span style="color:#008000; font-style:italic;"># create a new instance</span> mw = EEG.<span style="color:#9900CC;">new</span> mw.<span style="color:#9900CC;">update</span> = <span style="color:#0000FF; font-weight:bold;">true</span>   <span style="color:#008000; font-style:italic;"># mw.log.level = Logger::INFO</span>   <span style="color:#008000; font-style:italic;"># if we hit ctrl+c then just stop the run()-method</span> <span style="color:#CC00FF; font-weight:bold;">Signal</span>.<span style="color:#CC0066; font-weight:bold;">trap</span><span style="color:#006600; font-weight:bold;">(</span><span style="color:#996600;">"INT"</span><span style="color:#006600; font-weight:bold;">)</span> <span style="color:#9966CC; font-weight:bold;">do</span> mw.<span style="color:#9900CC;">stop</span> <span style="color:#9966CC; font-weight:bold;">end</span>   <span style="color:#008000; font-style:italic;"># Create a new Thread</span> thread = <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">{</span> mw.<span style="color:#9900CC;">run</span> <span style="color:#006600; font-weight:bold;">}</span> <span style="color:#008000; font-style:italic;"># ..and run it</span>   <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">"Starting..."</span> thread.<span style="color:#9900CC;">join</span>   <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">"Cleaning up.."</span> mw.<span style="color:#9900CC;">close</span> <span style="color:#6666ff; font-weight:bold;">RPi::GPIO</span>.<span style="color:#9900CC;">clean_up</span> <span style="color:#006666;">22</span></pre></div></pre> <p> <video controls="" height="360" width="480"><source src="/sites/default/files/DateiUploads/mindwave_led_lightup.mp4" type="video/mp4"></source></video></p> <h2>Automization</h2> <p>Automization is a very important part of our work at <a href="http://www.toscom.at/">Toscom</a>. I believe that sysadmins should automize as much as possible. Not only to be more efficient but also for quality management. So we do not configure servers manually but program the configuration and reuse this code as often as possible. This makes the next step very easy. I just install the configurations-management-system <a href="https://www.ansible.com/">Ansible</a> on the raspberry pi, download some (wordpress related) ansible-roles from <a href="https://galaxy.ansible.com/">ansible-galaxy </a>and call ansible-playbook within my script. Since Version 2 Ansible also includes modules for controlling <a href="https://aws.amazon.com/">Amazon AWS-Services</a>. So I will create my virtual machine in the Amazon-Cloud. Here is my playbook.yml:</p> <pre> <code> - hosts: localhost connection: local gather_facts: False tasks: - name: Provision Wordpress Instance ec2: aws_access_key: "MY-ACCESS-KEY" aws_secret_key: "MY-SUPER-SECRET-ACCESS-KEY" key_name: pi_key instance_type: t2.micro image: ami-ed82e39e wait: true wait_timeout: 500 assign_public_ip: yes vpc_subnet_id: subnet-de3b5da8 region: eu-west-1 group_id: sg-75d3c412 register: ec2 - name: Add new instance to host group add_host: hostname={{ item.public_ip }} groupname=launched ansible_user=ubuntu with_items: '{{ec2.instances}}' - name: Wait for SSH to come up wait_for: host={{item.public_dns_name}} port=22 delay=60 timeout=320 state=started with_items: '{{ec2.instances}}' - name: install wordpress hosts: launched become: True gather_facts: True vars: wp_mysql_host: 'localhost' session_post_max_size: '128M' session_upload_max_filesize: '128M' session_max_input_time: '70' session_max_execution_time: '90' roles: - valentinzberea.wordpress </code></pre> <p>I use the following roles (from <a href="https://galaxy.ansible.com/">ansible-galaxy</a>):</p> <ul><li>mats116.nginx        </li> <li>valentinzberea.wordpress</li> <li>mats116.mariadb-server    </li> <li>valentinzberea.hhvm</li> </ul><h2>Proof of Concept</h2> <p>In the next video clip, I recorded a proof of concept. First I got a connection with my headset (the light turns blue), then it took me a while to be focused. As soon as I have a focus level of 80, my program will turn on a LED and call ansible-playbook. In the clip we will see that in my Amazon AWS-Console a new virtual machine will start and install Wordpress, MariaDB and Nginx. At the end of the clip, I will copy the IP-address of the new host and connect to the Wordpress-Page on it.</p> <p> <video controls="" height="360" width="480"><source src="/sites/default/files/DateiUploads/mindcontrol_aws_wordpress.mp4" type="video/mp4"></source></video></p> <p>I did not use the Wave-Stream of the EEG-Data to detect the thoughts but only read out the attention-level of my mind. I also exited the script as soon as it fired up a command, otherwise I would have multiple command-executions on "long" thoughts aso.</p> <h2>Problems</h2> <ol><li>I cheated. I did not use the wave-data at all. I just used the attention-level I got from the Mindwave-Headset.</li> <li>This is difficult to use. How does one deliberately hold a focus with his mind? Some practice is needed...</li> <li>What if someone focuses longer? A timer is needed then, otherwise it toggles many times in a row</li> </ol><h2>Conclusion</h2> <p>I triggered a command with my mind which created a virtual machine (Amazon EC2-Instance), installed MariaDB, Nginx and Wordpress. That is one of my daily tasks and I was able to make it just by concentrating. If I combine this project with my <a href="https://tech.feedyourhead.at/content/controlling-power-outlets-using-the-rapberry-pi">power-outlets</a>, I could even make tea with my mind. It's not perfect. This technique is not very precise (neither is this headset). Even though I am very happy with the result. Maybe I will go deeper and compare signatures of EEG data to detect different states of mind.</p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Sep 16 2016</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Linux" hreflang="en">Linux</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/hackaday" hreflang="en">HackADay</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/raspberry" hreflang="en">Raspberry</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/ruby" hreflang="en">Ruby</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/hardware" hreflang="en">Hardware</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/taxonomy/term/97" hreflang="en">Toscom</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=200&amp;2=comment&amp;3=comment" token="2BmXclPgiIaQ8G9zkGASPYUrQx8quVImoHS9NOI2gYA"></drupal-render-placeholder> </section> Fri, 16 Sep 2016 07:06:56 +0000 Hoti 200 at https://tech.feedyourhead.at Ruby: pack / unpack https://tech.feedyourhead.at/content/ruby-pack-unpack <span class="field field--name-title field--type-string field--label-hidden">Ruby: pack / unpack</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>I found this very <a href="http://blog.bigbinary.com/2011/07/20/ruby-pack-unpack.html">nice article about pack/unpack with ruby</a>.</p></div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Aug 05 2016</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/external" hreflang="en">External</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/ruby" hreflang="en">Ruby</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=194&amp;2=comment&amp;3=comment" token="M_aCTAKnHqaiueHdQ4RSMCRKwc7sQ2HuG0eClWlFalU"></drupal-render-placeholder> </section> Fri, 05 Aug 2016 08:08:33 +0000 Hoti 194 at https://tech.feedyourhead.at Installing cronjobs out of scripts https://tech.feedyourhead.at/content/installing-cronobs-out-of-scripts <span class="field field--name-title field--type-string field--label-hidden">Installing cronjobs out of scripts</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Sometimes it's necessary to install cronjobs out of scripts. It's not a good idea to directly write to /var/spool/cron/crontabs. Various things might happen like permission problems or simply problems with the format. It's better to make this in two steps.</p> <p>First create a crontab-file, like /tmp/mytmpcronfile0001:</p> <pre> <code> */5 * * * * echo hello world &gt;&gt; /tmp/hello.txt 30 22 * * * echo foo bar &gt;&gt; /tmp/hello.txt </code></pre> <p>Now we can install this crontab for the current user by calling crontab:</p> <pre> <code> crontab /tmp/mytmpcronfile0001 </code></pre> <p>To list all cronjobs we can use:</p> <pre> <code> crontab -l </code></pre> <p>User root is also able to install cronjobs for other users:</p> <p>&nbsp;</p> <pre> <code> crontab -u someuser /tmp/mytmpcronfile0001 </code></pre> <h2>Let's do this in Ruby</h2> <p>The following code demonstrates how we can do this in Ruby. There is no error handling in this code, so be aware of this if you want to use it.</p> <pre> <code> #!/usr/bin/env ruby class Crontab attr_accessor :hour attr_accessor :min attr_accessor :mday attr_accessor :month attr_accessor :wday attr_accessor :command def initialize @hour = '*' @min = '*' @mday = '*' @month = '*' @wday = '*' @command = "/bin/false" end end class Crony attr_accessor :cronfile def initialize(file) @cronfile = file end def readfile ret = Array.new if not File.exist?(@cronfile) raise "File doesn't exist" end file = File.open(@cronfile,"r") file.each do |line| if line !~ /^\s*#/ h = parse(line) ret.push(h) end end file.close return ret end def writefile(hashy) file = File.open(@cronfile,"w") hashy.each do |cron| file.write("#{cron.min} #{cron.hour} #{cron.mday} #{cron.month} #{cron.wday} #{cron.command}\n") end file.close command = "crontab #{@cronfile}" `#{command}` end def parse(line) c = Crontab.new if line =~ /(\*|\d+)\s(\*|\d+)\s(\*|\d+)\s(\*|\d+)\s(\*|\d+)\s(.+)$/ c.min = $1 c.hour = $2 c.mday = $3 c.month = $4 c.wday = $5 c.command = $6 else raise "Invalid cron-entry" end return c end end crony = Crony.new("/tmp/some_cronjob") arr = Array.new day = Crontab.new day.hour= "09" day.min="30" day.command='echo hello day &gt;&gt; /tmp/hello.txt' arr.push(day) night = Crontab.new night.hour= "22" night.min="45" night.command='echo hello night &gt; hello.txt' arr.push(night) crony.writefile(arr) </code></pre> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Jun 26 2016</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Linux" hreflang="en">Linux</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/shell" hreflang="en">Shell</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/sysadmin" hreflang="en">Sysadmin</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/ruby" hreflang="en">Ruby</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=187&amp;2=comment&amp;3=comment" token="E8YRA-WZI5mgI4ZetMVPNxh-icTg9th1BGee-7sXC8E"></drupal-render-placeholder> </section> Sun, 26 Jun 2016 08:31:19 +0000 Hoti 187 at https://tech.feedyourhead.at Simple WebApp-Stress-Tool https://tech.feedyourhead.at/content/simulty <span class="field field--name-title field--type-string field--label-hidden">Simple WebApp-Stress-Tool</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>I wrote a simple webapp-stress-tool. <a href="https://github.com/whotwagner/simulty">Simulty</a> is a very simple webapp-stress-tool. It reads random urls from a file and executes multiple get-requests simultaneously to them.</p> <h2>Download:</h2> <pre> <code> git clone https://github.com/whotwagner/simulty </code></pre> <h2>Usage:</h2> <p>Create a file with one url per line and start the stresstest with:</p> <pre> <code> ./simulty.rb <urlfile> <number-of-threads> </number-of-threads></urlfile></code></pre> <h2>Sample-Urlfile:</h2> <pre> <code> http://www.somefoobar.com/index.php?fun https://www.somefoobar.com/user/login.php http://www.somefoobar.com/whatever/somewhere/over/the/rainbow.php </code></pre> <p>Tip: This Urlfile could be generated from a logfile.</p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Apr 22 2016</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/downloads" hreflang="en">Downloads</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/ruby" hreflang="en">Ruby</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/network" hreflang="en">Network</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/web" hreflang="en">Web</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/taxonomy/term/97" hreflang="en">Toscom</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=177&amp;2=comment&amp;3=comment" token="PTQEqErQeUkRAVDafW9aRuz25ARuUyrr5dGbKFPfnqI"></drupal-render-placeholder> </section> Fri, 22 Apr 2016 10:25:55 +0000 Hoti 177 at https://tech.feedyourhead.at Oneliner: Permutation using ruby https://tech.feedyourhead.at/node/159 <span class="field field--name-title field--type-string field--label-hidden">Oneliner: Permutation using ruby</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><pre><code> ➜ ~ ruby -e 'puts %w[t o m].permutation.map &:join' tom tmo otm omt mto mot </code></pre> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Feb 11 2016</span> <div class="field field--name-field-tagies field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class='field__items'> <div class="field__item"><i class="fa fa-tags"></i> <a href="/Programming" hreflang="en">Programming</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/one-liner" hreflang="en">One-Liner</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/ruby" hreflang="en">Ruby</a></div> <div class="field__item"><i class="fa fa-tags"></i> <a href="/tags/shell" hreflang="en">Shell</a></div> </div> </div> <section class="field field--name-comment-node-blog field--type-comment field--label-hidden comment-wrapper"> </section> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class='title comment-form__title'> <i class="fa fa-comments-o"></i> Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=159&amp;2=comment&amp;3=comment" token="boLbu0V8PzQYSsRX_Z2818fhtWSClp-Z4c11kqd36is"></drupal-render-placeholder> </section> Thu, 11 Feb 2016 07:38:32 +0000 Hoti 159 at https://tech.feedyourhead.at check_seleniumtime https://tech.feedyourhead.at/content/checkseleniumtime <span class="field field--name-title field--type-string field--label-hidden">check_seleniumtime</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Nagios-Check which loads a website in firefox and outputs the response-time of a website</p> <h3>Usage:</h3> <pre> <code> ./check_seleniumtime -h Usage: ./check_seleniumtime [ options ] -H -h, --help This help screen -d, --debug Enable debug-output -p, --perf Performance Data on or off -w, --warn RESPONSETIME Warning. default 3.5sec -c, --crit RESPONSETIME Critical. default 4.5sec -H, --host URL Website -s, --ssl enable ssl -P, --port PORTNUMBER used port -u, --uri used uri. for example: /impressum.html ./check_seleniumtime -H tech.feedyourhead.at OK: http://tech.feedyourhead.at 1.055 </code></pre> <h3>Requirements</h3> <ul> <li>apt-get install ruby firefox xvfb</li> <li>gem install selenium-webdriver</li> <li>gem install headless</li> </ul> <h3>Credits</h3> <p>This plugin is powered by <a href="http://www.toscom.at">Toscom</a></p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Oct 12 2015</span> <div class="clearfix text-formatted field field--name-field-md5sum field--type-text field--label-above"> <div class="field__label">md5sum</div> <div class="field__item"><p>3f18bd1e4fdd22e791de92921d9292a2</p> </div> </div> <div class="clearfix text-formatted field field--name-field-sha256sum field--type-text field--label-above"> <div class="field__label">sha256sum</div> <div class="field__item"><p>296e3ce2af725b4508b0abcc87563eb4fdc717dd2fe7b81b1d67feb78100a0a0</p> </div> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class="field__items"> <div class="field__item"><a href="/tags/download" hreflang="en">Download</a></div> <div class="field__item"><a href="/tags/selenium" hreflang="en">Selenium</a></div> <div class="field__item"><a href="/Nagios" hreflang="en">Nagios</a></div> <div class="field__item"><a href="/tags/nagios-check" hreflang="en">Nagios-Check</a></div> <div class="field__item"><a href="/tags/ruby" hreflang="en">Ruby</a></div> <div class="field__item"><a href="/Programming" hreflang="en">Programming</a></div> </div> </div> <section class="field field--name-comment-node-download field--type-comment field--label-hidden comment-wrapper"> </section> Mon, 12 Oct 2015 07:08:05 +0000 Hoti 118 at https://tech.feedyourhead.at facts2dw https://tech.feedyourhead.at/content/facts2dw <span class="field field--name-title field--type-string field--label-hidden">facts2dw</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>facts2dw.rb&nbsp; is a simple script which converts ansible(tested with&nbsp;1.9.2)&nbsp; facts into dokuwiki-format and uploads it via xmlrpc-interface into dokuwiki This script uses http-basic-authentication and ssl to login into dokuwiki. Ansible caches all the facts in &lt;ANSIBLE-DIR&gt;/facts so it is quite easy to import all facts into dokuwiki using the following line:</p> <pre> <code> for i in `ls *`; do facts2dw.rb $i; done </code></pre> <p>To upload all the changes whenever they occur I would suggest to use inotify. It is very easy to change this script to use puppet-facts instead of ansible-facts. If puppetdb is installed all the facts can fetched via the rest interface. It's just a matter of few lines. Of course the jason-structur will look different, but it will be easy to modify this very simple script. I would recommend to use the debug-code which executes 'pp', to dump the jason-hash.</p> <p>BTW: <a href="https://www.dokuwiki.org/devel:xmlrpc">don't forget to configure the xmlrpc-access in dokuwiki proberly!</a></p> <p>&nbsp;</p> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/users/hoti" typeof="schema:Person" property="schema:name" datatype="">Hoti</span></span> <span class="field field--name-created field--type-created field--label-hidden">Sep 24 2015</span> <div class="clearfix text-formatted field field--name-field-md5sum field--type-text field--label-above"> <div class="field__label">md5sum</div> <div class="field__item"><p>9f419544609f2539f79390e8f121a678</p> </div> </div> <div class="clearfix text-formatted field field--name-field-sha256sum field--type-text field--label-above"> <div class="field__label">sha256sum</div> <div class="field__item"><p>d25806bd0d8edf36caf6405e450c9dcd5e40ae5fa7d7ee16c6aabc5ecc1f090b</p> </div> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field__label">Tags</div> <div class="field__items"> <div class="field__item"><a href="/tags/downloads" hreflang="en">Downloads</a></div> <div class="field__item"><a href="/tags/ruby" hreflang="en">Ruby</a></div> <div class="field__item"><a href="/tags/ansible" hreflang="en">Ansible</a></div> <div class="field__item"><a href="/tags/puppet" hreflang="en">Puppet</a></div> <div class="field__item"><a href="/Programming" hreflang="en">Programming</a></div> <div class="field__item"><a href="/tags/sysadmin" hreflang="en">Sysadmin</a></div> </div> </div> <section class="field field--name-comment-node-download field--type-comment field--label-hidden comment-wrapper"> </section> Thu, 24 Sep 2015 13:18:36 +0000 Hoti 111 at https://tech.feedyourhead.at