Skip to content

Instantly share code, notes, and snippets.

View IQAndreas's full-sized avatar

Andreas Renberg IQAndreas

View GitHub Profile
@IQAndreas
IQAndreas / EntityFishHook.java
Created February 14, 2013 15:48
Partial from MineCraft decompiled source - `EntityFishHook::onUpdate()`
if (this.ticksCatchable > 0)
{
--this.ticksCatchable;
}
else
{
short var28 = 500;
if (this.worldObj.canLightningStrikeAt(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY) + 1, MathHelper.floor_double(this.posZ)))
{
@IQAndreas
IQAndreas / require-clean-git-index.sh
Created February 16, 2013 21:22
Shell function that requires that a GIT index is clean before running a command. The script allows modified or untracked files to exist in the repository, so long as the index is empty.
function require_clean_index()
{
# TODO: Allow to manually set which git directory
git diff-index --quiet --cached HEAD
if [ $? -ne 0 ]; then
echo "This command requires a clean index. Please reset or commit changes and try again.";
exit 2;
fi
}
@IQAndreas
IQAndreas / gist:5036465
Last active November 14, 2016 18:52
Their bracket placement and indentation is like some sick, twisted joke meant to confuse and torment me. (from http://opensteer.svn.sourceforge.net/viewvc/opensteer/trunk/plugins/Soccer.cpp?revision=181&view=markup ) It looks like the only problem is the "else" on line 14. Wrong, keep looking and it will start hurting your eyes.
if(collisionAvoidance != Vec3::zero)
applySteeringForce (collisionAvoidance, elapsedTime);
else
{
float distHomeToBall = Vec3::distance (m_home, m_Ball->position());
if( distHomeToBall < 12.0f)
{
// go for ball if I'm on the 'right' side of the ball
if( b_ImTeamA ? position().x > m_Ball->position().x : position().x < m_Ball->position().x)
{
@IQAndreas
IQAndreas / Playvideo.as
Created March 15, 2013 16:32
See: http://www.gotoandlearn.com/play.php?id=114 Loads the video in at runtime rather than from a SWC.
package {
import com.transmote.flar.FLARManager;
import com.transmote.flar.marker.FLARMarker;
import com.transmote.flar.marker.FLARMarkerEvent;
import flash.display.Sprite;
import flash.events.Event;
import flash.media.Video;
import org.libspark.flartoolkit.support.pv3d.FLARCamera3D;
@IQAndreas
IQAndreas / gist:5195397
Created March 19, 2013 11:30
Found this HTML comment in the source of a website. Via https://www.udacity.com/
<!-- Fix IE's mind-blowing idiocy -->
<script type="text/javascript" charset="utf-8">
if (!window.console) {
window.console = {};
}
if (!window.console.log) {
window.console.log = function () {};
}
if (!window.console.error) {
window.console.error = function () {};
@IQAndreas
IQAndreas / gist:5200218
Created March 19, 2013 21:14
Seek and Flee steering behaviors using OpenSteer ("orbiting" result)
// function init()
seekVehicle = new SimpleVehicle();
seekVehicle.setPosition(Math.random() * displayWidth, 0, Math.random() * displayHeight);
seekVehicle.radius = 10;
seekVehicle.maxForce = 800.0; //steering force
seekVehicle.maxSpeed = 300.0; //velocity
seekVehicle.speed = 100;
seekBoid = this.addBoid(seekVehicle, 0x00CC00);
// function update(currentTime:Number, elapsedTime:Number)
package
{
public const TAU:Number = Math.PI * 2;
}
@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
{
@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()
{
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 protected]'
link: 'http://iqandreas.github.com'
comment: 'Hello world!
This is a multi-line comment.