Skip to content

Instantly share code, notes, and snippets.

View quakeboy's full-sized avatar

Rajavanya Subramaniyan quakeboy

View GitHub Profile
SaveMethod(string filename, IDateTimeProvider dateTime, IFileManager fileManager);
//non unit-testable code
class Saver
{
void SaveMethod(string filename)
{
//do everything else before the following calls
DateTime dateTime = DateTime.Now();
FileManager.Save(filename, dateTime.ToString());
}
}
//code
int amazingAddMethod(int a, int b)
{
return a+b;
}
//test
void testForAmazingAddMethod(int a, int b)
{
for (int a = 0; a < 10; a++)
@quakeboy
quakeboy / This is a test blog post for roughdraft
Last active September 14, 2015 09:31
This is a test blog post for roughdraft.md
## Hey there ##
**This is important, leave immediately**
*has never worked for anyone ever*
@quakeboy
quakeboy / Unity3dMouseHitTest.cs
Last active January 3, 2021 18:11
Unity3d mouse hit test with any 3d box collider
void Update ()
{
if ( Input.GetMouseButtonDown(0) )
{
Ray inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit myHitInfo = new RaycastHit();
if ( GetComponent<BoxCollider>().Raycast(inputRay, out myHitInfo, 10000f ) )
Debug.Log("Clicked");
@quakeboy
quakeboy / SaveLoadAS3ClassSharedObjects
Last active December 29, 2015 15:09
Saving and loading AS3 classes from SharedObjects
private var so:SharedObject = SharedObject.getLocal("Demo");
public function saveResClass(cls:Class):void
{
this.storeValue("lastClass", getQualifiedClassName(db));
}
public function loadResClass():Class
{
var className:String = so.data["lastClass"];
@quakeboy
quakeboy / StarlinScene.as
Last active December 26, 2015 00:49
Starling with AS3 Graphics class
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.CapsStyle;
import flash.display.Sprite;
import flash.filters.BitmapFilter;
import flash.filters.GlowFilter;
import flash.geom.ColorTransform;
@quakeboy
quakeboy / vector to direction index for 8 directional movement and sprite state settings
Created August 17, 2013 11:15
Converting angle to indexes, or vector -> angle -> indexes.. I have done this at least 4 times in my life for various games/projects before, yet have to do it each time again. So here is a gist for it
float degangle = atan2f(t_dir.x, t_dir.y)*180/M_PI;
//pushing it down, so that -22.5 becomes the new 0
degangle += 22.5f;
//now making the final range as 0 - 360
if (degangle < 0) degangle += 360;
//now this var is ranged 0 - 7, with -22.5f to 22.5f being 0 and so on...
m_DirectionIndex = (int)floorf(degangle/22.5f);
@quakeboy
quakeboy / Calculating Clicks per minute
Last active December 21, 2015 04:29
Calculating clicks per minute based on mouse clicks. Needed to calculate something for my game
if (e.type == MouseEvent.MOUSE_DOWN)
{
if (last_dt == 0) //first time. no avg yet.
{
last_dt = getTimer();
}
else
{
if (new_dt == 0) //second time, first cps, first average
{
@quakeboy
quakeboy / Horizontal Water
Created March 14, 2013 16:23
Horizontal Water - 2 variations
#ifdef GL_ES
precision highp float;
#endif
uniform float time;
uniform vec2 resolution;
uniform vec4 mouse;
uniform sampler2D tex0;
uniform sampler2D tex1;