Skip to content

Instantly share code, notes, and snippets.

View IQAndreas's full-sized avatar

Andreas Renberg IQAndreas

View GitHub Profile
@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 protected]'
link: 'http://iqandreas.github.com'
comment: 'Hello world!
This is a multi-line comment.
If an apostrophe is found, it''s doubled.'
@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 / 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 / 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 / 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: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 / BlockLeaves_snippet.java
Last active December 19, 2015 15:29
Snippet from MineCraft's BlockLeaves.java showing the leaf decay code.
/**
* Ticks the block if it's been scheduled
*/
public void updateTick(World world, int leafX, int leafY, int leafZ, Random random)
{
if (!world.isRemote)
{
int meta = world.getBlockMetadata(leafX, leafY, leafZ);
//If bit 0x8 is set, the leaves will be checked for decay.
@IQAndreas
IQAndreas / test
Last active December 21, 2015 07:49
Running this script in terminal (via just a standard `./test`) will execute the script located in `/home/andreas/custom-script` passing this file as the first argument
#!/home/andreas/custom-script
This will not be treated as code, but if executed in shell,
the script located in `/home/andreas/custom-script`
will run and be executed, passing the path to this
file as the first parameter.
@IQAndreas
IQAndreas / helloWorld.java
Last active December 21, 2015 08:09
Want to run Shell/Bash commands but are sick and tired of how sickeningly untyped they are? Introducing JavaSH!
#!/bin/javash
# Both Bash and Java comments supported (not a feature, I was just too lazy to force one or the other)
// Some basic commands are included
echo("Hello world!");
// Others, you have to manually run
String currentDir = run("pwd");
echo(currentDir);
@IQAndreas
IQAndreas / profile
Last active December 22, 2015 20:19 — forked from wolever/profile
# prompt examples:
# [3 jobs master] ~/code/myproject/foo
# [1 job my-branch] ~/code/bar/
# ~
# Very, very fast, only requiring a couple of fork()s (and no forking at all to determine the current git branch)
if [[ "$USER" == "root" ]]
then
export PS1="\e[1;31m\]\u \[\e[1;33m\]\w\[\e[0m\] ";
else