Skip to content

Instantly share code, notes, and snippets.

View IQAndreas's full-sized avatar

Andreas Renberg IQAndreas

View GitHub Profile
@IQAndreas
IQAndreas / gist:5695249
Created June 2, 2013 22:57
Cleaned up version of this awful code: https://gist.github.com/IQAndreas/5692007
// This code sets up the input box to auto-complete
$("#step1-search-address-input").autocomplete({
source: map.getAutocompleteData,
select: map.onAutocompleteSelect
});
// This code is contained in the Map class
Map.prototype.initialize = function()
{
@IQAndreas
IQAndreas / gist:5692481
Created June 2, 2013 03:09
Unless I am mistaken, FireFox allows optional parameters in functions, Chrome does not.
<script type="text/javascript">
function optional(required, optional = 5)
{
console.log(required, optional);
}
optional("a", "b");
optional("c");
optional();
</script>
@IQAndreas
IQAndreas / gist:5692007
Created June 1, 2013 23:04
Can someone tell me just by looking what this code does, and which brackets refer to functions or dynamic objects? Taken from http://gerger.co/blog/2011/02/17/google-maps-api-v3-location-search-with-jquery-autocomplete-plugin/
$(document).ready(function(){
var mapOptions = {
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: new google.maps.LatLng(41.06000,28.98700)
};
var map = new google.maps.Map(document.getElementById("map"),mapOptions);
@IQAndreas
IQAndreas / log.as
Created May 5, 2013 02:23
Log flash data both to `trace` and the JavaScript console.
package
{
import flash.external.ExternalInterface;
/** Will send the text to trace and JavaScript console (if available)
* Only to be used for debugging. Not to be used for final release! */
public function log(...args:*) : void
{
//Nothing to log
if (args.length <= 0) { return; }
@IQAndreas
IQAndreas / switch_comparison.as
Created April 16, 2013 15:52
"switch" to check the minimum drinking age (sample). Comparison between AS3 and HaXe. (partial list from http://en.wikipedia.org/wiki/Legal_drinking_age)
// AS3
switch (country)
{
case ITALY:
case LUXEMBOURG:
age = 16;
break;
case UK:
case SWEDEN:
case FRANCE:
@IQAndreas
IQAndreas / comment-001.yaml
Created April 14, 2013 23:49
Only the required fields for a comment used with the Jekyll Static Comments system
post_id: /actionscript/why-my-one-line-if-statements-are-unusual
date: 2013-04-14 14:36
name: 'Andreas Renberg'
email: 'email@site.com'
link: 'http://iqandreas.github.com'
comment: 'Hello world!
This is a multi-line comment.
If an apostrophe is found, it''s doubled.'
post_id: /actionscript/why-my-one-line-if-statements-are-unusual
date: 2013-04-14 14:36
post_title: 'Why my one line if statements are unusual'
return_url: 'http://IQAndreas.github.com/actionscript/why-my-one-line-if-statements-are-unusual/'
name: 'Andreas Renberg'
email: 'email@site.com'
link: 'http://iqandreas.github.com'
comment: 'Hello world!
This is a multi-line comment.
@IQAndreas
IQAndreas / gist:5317083
Last active December 15, 2015 20:18
Pseudocode for your average day of coding. (In my case, "coffee" is replaced with "tea".)
coffee.fill();
while (coding)
{
coffee.temperature--;
if (coffee.temperature <= 0)
rememberAboutCoffee();
}
function rememberAboutCoffee()
{
@IQAndreas
IQAndreas / gist:5308731
Created April 4, 2013 08:26
Closest difference to (can be used for angles)
// Taken (with some modifications) from http://actionsnippet.com/?p=1451
private function difference(angle1:Number, angle2:Number, max:Number = 360):Number
{
const m:Number = max / 2;
var v:Number = ((angle1 - angle2 + m) % max);
return (v > 0) ? (v - m) : (v + m);
}
private function getClosestTime(hoursProgress:Number, index:int):int
{
package
{
public const TAU:Number = Math.PI * 2;
}