js: window.performance on mobile

I’d been playing around with some graphically intensive tests in javascript and openGL, but when I went to test them on various mobile devices, huge aspects of them were failing. After a few minutes I realized that window.performance.now was missing. Here’s a shim I found that does the trick.

(function(){
  if ("performance" in window == false) {
      window.performance = {};
  }
  Date.now = (Date.now || function () {
    return new Date().getTime();
  });
  if ("now" in window.performance == false){
    var nowOffset = Date.now();
    if (performance.timing && performance.timing.navigationStart){
      nowOffset = performance.timing.navigationStart
    }
    window.performance.now = function now(){
      return Date.now() - nowOffset;
    }
  }
})();

the above polyfill is // copyright Paul Irish 2015

bash: some useful terminal commands

I found myself constantly needing to repeat some tasks from the terminal: open pages in chrome from the terminal. Open folders, especially bin. Run a simple python http server and give it a specific port. And setup watching and mapping on CoffeeScript files.

So here’s some bash scripts to do those things. I named mine chromeopen, openbin, pserver, and coffeewatch. chromeopen takes a single file name, and pserver will run using the port number if one is provided.

#!/bin/bash
open -a Finder /usr/local/bin
#1/bin/bash
if(($# != 1))
then
  echo "Requires a filename to open"
  exit 1
fi
open -a "/Applications/Google Chrome.app" $1
#!/bin/bash
if [ "$#" -ne 1 ]
then
  python -m SimpleHTTPServer
else
  python -m SimpleHTTPServer $1
fi
#!/bin/bash
coffee --output compiled --map --watch --compile ./

bash: script for making bash scripts

I had been on a bash script kick, adding shortcuts to run coffee script watching, or SSH’ing into different places, and realized that I could just write a bash script that would create a basic script file, with all the file permissions, place it in my bin folder, then open it in sublime for me to add the relevant code. Obviously you can change the ‘subl’ command to open it in your editor of choice.

#!/bin/bash

if(("$#" != 1))
then
  echo "Requires Command Name as Argument"
  exit 1
fi

COMMANDNAME=$1

 pushd /usr/local/bin/scripts
 touch $COMMANDNAME
 echo '#!/bin/bash' > $COMMANDNAME
 chmod 755 $COMMANDNAME
 subl $COMMANDNAME
 popd

vim: all you need to…reference

Choosing to go into Vim is a complicated thought process. From the terminal, you’ll need these two commands:

 vimtutor //pretend you are going to learn to use Vim
 vim //with optional filename to to open

___

Once you’re in Vim, most likely because $>git commit put/trapped you there without you wanting to go. Use these:

  i   //enter insert mode, now write code
  esc //exit insert mode
  :wq //writefile and quit

js: div actions

divAction.js

I made a simple demo framework for animating divs using composite actions for position, scale, and rotation. I was tired of manipulating css for demoing things. I just wanted to instantiate a class, and then call methods on it to animate, much like you would in cocos2d or SpriteKit.

It’s actually a pretty performant little streamlined package. It updates all actions per frame using requestAnimationFrame. It was meant for demoing and presentations, but it could do more.

demo.js contains the examples for how to:

–instance a Thing, which is just a class wrapped around a div.
–add actions to a Thing to move it, rotate it and scale it.
–the top portion has demo flags to force fixed intervals, and lower performance, all just for the purpose of discussion.
–Note: actions are composite, which means if you add 2 movement actions to a Thing, then the thing will be updating each frame based on both actions.

Since everything is just a div, you could add CSS classes and files, use standard button and click and link commands, etc.

For demo purposes the code in the Thing/actions is not very dry, if you were going to really use this to do anything, you’d want to make an action class and create instances of Actions and add them to Things. That way you could also easily pause or remove an individual action ahead of schedule.

Oh, and obviously all the objects have just simple names stored in global, so please wrap them up in something first.

https://github.com/CHBDev/divActions