• JavaScript: Find string in a string

    Quick snippet to find a string within a string in JavaScript: – var question = “ques_test”; if(question.includes(“ques_”)) {     console.log(“Question Found”); }  

  • PHP: Find string in a string

    Quick snippet to find a string in a string in PHP: – $question = ‘How are you?’; if (strpos($question, ‘are’) !== false) { echo ‘Found it’; }  

  • Closest point on a line

    Quick piece of code to find the closest point on a line segment from a point in 3D space: – /// <summary> /// Get the closest point (and distance) to line segment from a point in 3D space /// </summary> /// <param name=”a_sourcePoint”>Point that we’re finding the closest point to</param> /// <param name=”a_start”>Start of line…

  • Dot Product

    A simple definition of a dot product that I think works really well; “The dot product tells you what amount of one vector goes in the direction of another” Might help someone with their understanding of what a dot product actually is  

  • Unity Reading JSON Files

    So, this one always seems to mess me around so I’m writing it up so I’ve got an easy reference for next time. First we define the class we want to read the JSON into. This has to match to the format of the JSON (obviously) as it’s going to deserialize it. So, quick example…

  • PHP: Heredoc

    Heredoc is an easy way to echo html and Javascript content without having to worry about “‘s or adding ?> <?php all over the place. A simple example is as follows:- <?php // Lots of PHP code goes here $id=57; // Store the passenger number $string=<<<END <span class=”blah”>Heading</span> <span> <select name=”project” class=”moreBlah” onchange=”DoSomething($id);”> END; echo…

  • JavaScript: Post content to a php page

    So, you’re working in JavaScript and you need to pass content to a php page. On the JavaScript side, you do this: – var formData=new FormData(); formData.append(‘myString’, myString); var url=”./accessMyString.php”; xmlhttp=new XMLHttpRequest(); xmlhttp.open(“POST”, url, true); xmlhttp.send(formData); This will store the string (or anything else you need to pass) into ‘myString’ in the FormData and will…

  • PHP: Connect to a MySQL database, run a query and read a field

    Quick reference for how to read a single field from a MySQL database in PHP: – // Connect to the database $mysqli = new mysqli(my.server.com’, ‘schemaName’, ‘password’, ‘databaseName’) or die (‘<b>Could not connect: </b>’ . mysql_error()); // Query the database for the info we need $results = $mysqli->query(“SELECT * FROM myData WHERE id=’$id'”) or die($mysqli->error);…

  • JavaScript: Access element in iframe ‘A’ from iframe ‘B’

    So, I’ve got an iframe called “mainiframe” and I want to access an element in “subiframe”. As long as the “subiframe” has its name set to “subiframe”, all I have to do to find the element ‘test’ is: – var el = parent.subiframe.document.getElementById(“test”);  

  • iOS: Change device capabilities with a postProcessBuild step

    So, this one solves a bug in Unity 2017.4.2f2 that causes the armv7 device capability to be added to a 64 bit only build. We actually want arm64 instead of armv7 so I’ve setup this little hack to handle the fix   using UnityEngine; using UnityEditor; using UnityEditor.Callbacks; #if UNITY_IOS using UnityEditor.iOS.Xcode; #endif using System.IO;…