• Javascript: Run code every ‘x’ seconds

    Snippet of code to run code every second. Doesn’t trigger the next iteration until the first has finished. (function() { // Do something every second here setTimeout(arguments.callee, 1000); // 1000 is the time in milliseconds })();  

  • Installing Node.js on Windows

    Download the Windows installer from here Nothing complex. Just click the ‘Next’ until the installer finishes and then restart the PC. Once the PC has restarted, open a command line (or Bash Window) and type npm -v. If you get a version number then the install worked fine. To run js code, simply type node [file.js]…

  • Show array content in Javascript

    This will send an array to an alert. Handy for a quick debug: – alert(JSON.stringify(dict));    

  • Make a Mac sleep from the command line

    Nice and simple; pmset sleepnow        

  • Unity: Remove AR Support module

    If you’ve installed Vuforia and then decided that it’s a much smarter move to just use the ARKit plug-in instead then you can remove the AR-Support module by deleting it from your Unity install directory. Make sure you close Unity first C:\Program Files\[Unity2017.3.1]\Editor\Data\PlaybackEngines    

  • Unity: UnityEngine.Advertisements.dll could not be found

    If you’re seeing an error when building a Unity project with Jenkins on Windows, and it looks something like this… error CS0006: Metadata file ‘Unity/cache/packages/packages.unity.com/com.unity.ads@2.0.3/UnityEngine.Advertisements.dll’ could not be found …then it’s probably caused by Unity PackageManager (introduced in 2017.2) looking a file in the wrong place. Jenkins uses the SYSTEM account to access files, but…

  • Display local time in PHP

    Need to show the time in local time (Brisbane) instead of UTC: – $datetime = new DateTime; $otherTZ = new DateTimeZone(‘Australia/Brisbane’); $datetime->setTimezone($otherTZ); echo “Last Update” . $datetime->format(‘Y-m-d H:i:s’) . “<br /><br />”;        

  • C# Unix time from DateTime

    Single line to do this one: – Int32 unix = (Int32)(startTime.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; Takes the date and removes the number of seconds that have passed since 1/1/1970          

  • C# List Find and FindAll using Lambda

    Find a list of things that have a given member set to a given value: – List<Thing> foundThings = listOfThings.FindAll(x => x.member == searchParam); if(foundThings.Count == 0) return false; // Do something with the foundThings Find a single thing that matches a given criteria: – Thing thing = listOfThings.Find(x => x.member == searchParam); if (thing…

  • Clamping dates in PHP

    Needed to clamp a unix timestamp in PHP so I could use it for a database lookup. Quick source dump as follows: – $time = date_create()->getTimeStamp(); // Get the initial timestamp $mysqlDateTime = date(“Y-m-d H:i:s”, $time); echo “Before: ” . $mysqlDateTime . “<br />”; // Clamp to Minutes $time = floor($time / 60) * 60;…