Skip to main content

Posts

High Sierra and Valgrind Install

Valgrind is a tool used for memory management and profiling your applications.  I wanted to use it on my Macbook and ran into issues installing with brew and it turned out it wasn't too horrible of a change. brew update brew install --HEAD valgrind    Voila you now have a working run of valgrind. Happy Trails.

Serving static files in a directory.

A few different ways to serve static files in a directory on the fly for development. IIS Express C:\> "C:\Program Files (x86)\IIS Express\iisexpress.exe" /path:C:\MyWeb /port:8000 NodeJS $ npm install -g http-server $ http-server -p 8000 PHP $ php -S localhost:8000 Python 2 $ python -m SimpleHTTPServer 8000 Python 3 $ python3 -m http.server 8000 Ruby $ ruby -run -e httpd . -p 8000

Reverse a number without converting to a string.

Sometimes I like to work on coding problems just for fun. Things like Project Euler, Code Eval Hackerrank etc. Depending on what language you decide to do things in it might be easier and more efficient to think a little different. Some languages like Ruby, for example, converting a number to a string with to_str() and then reversing is rather trivial. But what if I want to solve it by keeping the number a number? Currently, I am playing around with Rust so my example will be in that language however you can use this same formula in whatever language you like. pub fn num_reverse(number: i32) -> i32 { let mut num = number; let mut rev = 0; while num > 0 { rev = rev * 10 + (num % 10); num = num / 10; } return rev; } Now that we have the code lets map out a little bit of how it works. Let us take the number 1234. num = 1234; rev = 0; Grab the first digit. rev = rev * 10 + (num % 10) Which can be written as. rev = 0 * 10 ...

Remote API useful tricks for Docker on Mac OS X

Install Socat Socat allow you to forward ports to a variety of things. For Docker forwarding a port to the docker.sock file makes a quick way to get access to the Docker remote api. Docker also allow a way to open up that TCP port however on Mac it is temperamental and hard to use brew install socat socat -d TCP-LISTEN:2375,reuseaddr,fork UNIX:/var/run/docker.sock & Create an IP alias Running Docker containers locally is a fairly common thing. Interconnectivity between containers works naturally. However, sometimes you may also want a container to connect back to the Docker Remote API. If you are constantly on the go changing networks you do not want to have to change that IP address every time. A great use case for this is running Jenkins and using docker slaves sudo ifconfig lo0 alias 192.168.99.50 Remote API There are also some interesting endpoints you can use for information curl http://localhost:2375 curl http://localhost:2375/containers/json curl http://l...

Mock HTTP calls with Angular and Protractor

One of the benefits using AngularJS is also using some test tools like Protractor. Protractor is a tool that was made for Angular testing. Many times when testing you will need to mock some data so that you can see if your application responds in the correct manner. Let us assume that we have the following HTML file running our application. <!doctype html> <html ng-app="demo"> <head> <title>Hello</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular-mocks.js"></script> <script src="hello.js"></script> </head> <body> <div ng-controller="Hello"> <p>Hello <span id="gname">{{exampleResponse.name}}</span></p> </div> ...

Build your own expectation library.

In the world of impending deadlines, testing is a key a vital role with any project. When building software you can test many functions and processes in a matter of minutes depending on how you setup your tests and how well the code was written to be testable. A key element for that tests is what you expect. Javascript for example, there are many expectation frameworks out there. Jasmine, Chai, Mocha to name a few. Let's build a simple expectation without their input. var expect = function(obj) { return {} } This will be our starting point for what we will expect. Very simply it is a function that will accept an argument obj and then it returns some object back that will be defined in more detail soon. You may be thinking one object? That doesn't seem quite right. For an expect statement to work shouldn't we have something like "expect(a, b, 'equal')". Yes, we could do something like that. However, for this example, we will attempt to make the co...

JSON Schema testing with Postman

Postman is becoming quite the popular tool for accessing and testing REST api services. One of the cool features is that you can write some Javascript tests on your responses. Built into Postman is also the Tiny Validator v4 and Cheerio. Cheerio is a small core JQuery like implementation. The problem I have is that there is no way to import a schema file from a remote place or a file. This will be about how I get around that issue. Pre-request Script var uri='http://someUrl.com'; $.get(uri + '/someFolder/schema.json', function(schema) { postman.setEnvironmentVariable('schema', JSON.stringify(schema)); }); This Pre-request script is what saves the day. There are a couple of timing issues that are present due to async processing. If you were to put this in your test script your chances of it not completing in time are very high and you would get inconsistent results. If you are familiar with JQuery the $.get should look familiar as a ajax call...

Javascript send text function

Simple send text function that you could use for front end tests within a browser. Replacing the value is quite easy with standard Javascript, however the DOM does not realize that the value has changed. For instance lets say you had an input field that is required to be filled in. If you just change the value by its self it will never remove the required message. To complete this we fire off a change event. function sendText(id, val) { //find the element var el = document.getElementById(id); //replace the value of the element with val el.value = val; //create an event to let the DOM know something changed. var event = new Event('change'); //fire off the event el.dispatchEvent(event); }

Display Guitar Chords on webpage

Sometimes its nice to have a handy tool for displaying different chords on a web page. For instance lets say that you want to show off some lyrics with chords to teach someone a song. I created ChordTab to have a simple way to display those chords. Code Sample <style> svg { width: 100px; } </style> <c-tab chord="g" instrument="guitar"> <script src="https://gitcdn.xyz/repo/blh0021/chordTab/master/src/tab.min.js"></script> Sample Chord Other Instruments In addition to guitar, you can also change the instrument attribute to mandolin, ukulele, or banjo. Currently not every chord has been created data wise but work is being done all the time.

Protractor getText from hidden element.

Ran across a point that I wanted to get the value of a hidden element while running my Protractor tests. getText() function was not helpful at all. In order for it to return text it has to be visible. There is an option called getAttribute('textContent'). This will allow you to always return the text. Sample HTML <span style="display: none" name="hiddenSpan">Hidden Text</span> Sample Protractor JS $('[name="hiddenSpan"]').getText(); // returns "" $('[name="hiddenSpan"]').getAttribute('textContent'); // returns "Hidden Text"

Get a little Rusty

Been playing around with Rust lang and I have to say I am starting to really enjoy it as a low level programming language.  Its kinda cool to have some modern functionality from the beginning.  Now as a software developer I can get excited but what about being a test developer.  One should probably think those are the same thing.  Well I wont start up that argument but I tend to believe they are one in the same. Lets do some basic coding. We can create us a new library called test_example. $ cargo new test_example This will create you a basic structure for a project. Included will be a src directory. Underneath that you will see lib.rs. You can open this up in your favorite text editor and see something that looks like. #[cfg(test)] mod test { #[test] fn it_works() { } } So you could run this right now and get some passing tests. $ cargo test Lets simplify what we are looking a little more. Change your lib.rs to look like. pub fn truthy(...

I-Team vs We-Team

Agile Agile Agile....  The loudest buzzword of many I get to hear lately.  Even though we hear it does it actually sink in to our everyday practices.  So many seem to know the Agile Manifesto to heart, and also the 12 principles.  What is interesting to me in working in some of the teams is that even though we call our team an agile team, it still acts like the old waterfall project work. I could spell out many reasons why I see conflicts that inject a lot of churn within the team.  However the biggest and I believe root cause is the word TEAM itself.   For instance within your own group have you ever said or heard something like, "we all should be responsible for the outcome"?  Then when someone is asked to do something a little outside their comfort zone they get mad or offensive and say "That is not my job", or "I do not feel qualified to do that." This is what I like to call the I-Team.  Or Individual Team.  In General these p...

Juniper VPN using OpenConnect

Finally there is a tool worth using for vpn besides the default from Juniper that works on Linux. Its rather quick to get started. Install Arch $ pacman -S openconnect Install Ubuntu $ apt-get install openconnect Install Fedora/RedHat $ dnf install openconnect or this if you have older Fedora/RedHat $ yum install openconnect Once you have it installed you may need to reboot. This will allow proper access to /dev/net/tun Run it $ openconnect --juniper vpn.domain.com

I'll Fly Away - Lyrics and Chords

VERSE 1: G Some glad morning when this life is o'er, C I'll fly away G To a home on God's celestial shore, C I'll fly away CHORUS: G I'll fly away, O glory, C I'll fly away G In the morning. G When I die, E hallelujah, by and by G I'll D I'll fly away VERSE 2: G When the shadows of this life have grown, C I'll fly away G Like a bird from prison bars has flown, C I'll fly away VERSE 3: G Just a few more weary days, and then, C I'll fly away G To a land where joys shall never end, C I'll fly away

Waiting for asynchronous calls in Protractor

Sometimes when dealing with tests the asynchronous objects are just a little ugly and hard to read. For instance if you have 3 buttons on a page and you wanted to make sure that all 3 were the same size. You would have to wrap all 3 elements together with a promise all. I am sure you can imagine the fun. With ES6 there is as new option to await asynchronous calls. First you will need to add some libraries to your project $ npm install babel-core babel-plugin-transform-async-to-generator Then you will need to add some information to the protractor-conf.js //You can add this either at the top of the file or you can put it within your onPrepare section. require('babel-core/register'); Now create a .bashrc file { "plugins": ["transform-async-to-generator"] } Now the fun part accessing the power of async and await. On you it statement we need to add an async. it('should give us text', async function() {... or like this if your are mor...

Query Selector: How to Or Selection

This is probably an odd topic, however I was recently asked how could one select between 2 possible elements on a browser using Protractor. If you are unfamiliar with Protractor it is a testing tool for AngularJS applications. To start lets show a code example of what we are looking at. <html> <body> <div id='ex1'> <!-- some code here --> </div> <div id='ex2'> <!-- some code here --> </div> </body> </html> Notice from the code that we have 2 divs with id's ex1 and ex2. Now depending on the code you ex1 or ex2 can be hidden. Lets say hypothetically they both do the exact same thing and you just want to click which ever one happens to be available. At the same time you also don't want to add expensive checks for isPresent or waits. To get around this you can do the following with the by.css query selector. $('[id="ex1"], [id="ex2"]') ...

Add Search to Blogger

Simple way to add a search to your blog on Blogger. Click -> Layout Click -> Add a Gadget Click -> HTML/Javascript Paste -> Code below <form action="/search" id="searchthis" method="get" style="display: inline;"> <input id="search-box" name="q" size="30" style="height: 30px;" type="text" /> <input id="search-btn" type="submit" value="Search" /> </form>

Docker Compose a Selenium Grid

There are times when you would like to Selenium Grid quickly so that it can scale to whatever testing goal is you want to achieve. To start out you will need to get Docker you can goto Docker.com to find out more information on installing. Create a docker-compose.yml Make a new directory and name a file docker-compose.yml inside that directory. The contents are below. hub: image: selenium/hub ports: - "4444:4444" chrome: image: selenium/node-chrome links: - hub expose: - "5555" firefox: image: selenium/node-firefox links: - hub expose: - "5555" Once you have created your file goto that directory in your command line. This will create your instances and download necessary files. $ docker-compose build To run your instances you can run the following and it will start your servers. $ docker-compose up At this point you can now point your test code to http://127.0.0.1:4444 as the selenium server. You will n...

Scrolling to place on webpage for Protractor or Webdriver testing.

Sometimes when using a Selenium by product like Protractor for testing Angular applications, I run into issues trying to access certain elements. In some cases it is because our UI folks may have another element that hovers over an area rather than actually take up that space. In cases like these I need to move the content on the page similar to how a user would so that the content I need is the front most element on the page. To do this I made a simple scrollTo function that will take a Selenium element and tell the browser with executeScript to goto those coordinates. I also have an offset so that I can move it around the would be elements that cover my element. function scrollToElement(element, offset) { offset = offset || 0; element.getLocation() .then( function(loc) { browser.executeScript(('window.scrollTo('+loc.x+','+ (loc.y - offset) +');')) }); }