Skip to content

Instantly share code, notes, and snippets.

View rikwatson's full-sized avatar

Rik Watson rikwatson

View GitHub Profile
@rikwatson
rikwatson / gist:8af5b6b0a760a747df0e
Created August 2, 2012 15:24
Some Catmull-Rom code scraped from the web
void PointOnCurve(TrackPoint &out, float t, TrackPoint p0, TrackPoint p1, TrackPoint p2, TrackPoint p3)
{
float t2 = t * t;
float t3 = t2 * t;
float tension = 0.5f;
out.x = 0.5f * ( ( 2.0f * p1.x ) +
( -p0.x + p2.x ) * t +
( 2.0f * p0.x - 5.0f * p1.x + 4 * p2.x - p3.x ) * t2 +
( -p0.x + 3.0f * p1.x - 3.0f * p2.x + p3.x ) * t3 );
@rikwatson
rikwatson / gist:3412741
Created August 21, 2012 06:44
Make an Activity Fullscreen
public class FullScreenActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
@rikwatson
rikwatson / gist:3422969
Created August 22, 2012 06:32
Android Analog Clock
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Full Screen
//
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
@rikwatson
rikwatson / gist:3688990
Created September 10, 2012 05:12
Javascript prototype example (Which you've seen 100's of times)
//Constructor. <em>this</em> is returned as new object and its
// internal [[prototype]] property will be set to the constructor's
// default prototype property.
//
var Circle = function(radius)
{
this.radius = radius;
// Next line is implicit, added for illustration only.
//
// this.__proto__ = Circle.prototype;
@rikwatson
rikwatson / gist:4722688
Created February 6, 2013 14:04
Flatten Tuple
# python: how to flatten a tuple
#
# Basically the problem was that I wanted to create a flat tuple from a tuple and a single value like such:
#
val = 3
tup = ( 'a', 3.14, "zzz" )
# I wanted this:
#
# ( 3, 'a', 3.14, "zzz" )
# Split a list.
# Given [1,2,3,4,5,6,7,8] & 3 returns [[1,2,3], [4,5,6], [7,8]]
#
L = [1,2,3,4,5,6,7,8]
C = 3
print [L:[i:i+C] for i in range(0, len(L), C)]
@rikwatson
rikwatson / example-csharpType.ps1
Created February 25, 2015 08:43
Use C# from PowerShell
$csharp = @"
public class TakeAway
{
public static int Minus(int a, int b)
{
return (a - b);
}
}
"@
Add-Type -TypeDefinition $csharp
@rikwatson
rikwatson / psake-test.ps1
Created February 25, 2015 08:44
An example of using the psake DSL within PowerShell
Task default -Depends Build
Task Build -Depends Init,Clean,Compile {
"build"
}
Task Compile -Depends Init,Clean {
"compile"
@rikwatson
rikwatson / _get_exportFolder.ps1
Created February 25, 2015 08:48
Create (if necessary) & returns a folder on the users desktop of the format yyyy-mm-dd which can be used to export stuff into.
<#
Create (if necessary) & returns a folder on the users desktop of the format yyyy-mm-dd which
can be used to export stuff into.
#>
function _get_exportFolder
{
param()
$exportFolder = Join-Path (Join-Path $env:USERPROFILE "Desktop") (Get-Date -Format yyyy-MM-dd)
@rikwatson
rikwatson / Script-Template.ps1
Created February 25, 2015 10:24
A basic powerShell script template showing best practices,
#requires -version 2
<#
.SYNOPSIS
<Overview of script>
.DESCRIPTION
<Brief description of script>
.PARAMETER <Parameter_Name>
<Brief description of parameter input required. Repeat this attribute if required>