Skip to content

Instantly share code, notes, and snippets.

View arxae's full-sized avatar

Andy Maesen arxae

View GitHub Profile
@arxae
arxae / Box2DBasic.cs
Last active December 23, 2015 17:29
Basic SFML.NET / Box2DX example
using System;
using System.Diagnostics;
using Box2DX.Collision;
using Box2DX.Common;
using Box2DX.Dynamics;
using SFML.Graphics;
using SFML.Window;
using Color = SFML.Graphics.Color;
namespace TestingSFML
@arxae
arxae / RendererExtensions.cs
Created October 24, 2013 14:48
Checks if an object is in view of a camera (Unity)
using UnityEngine;
public static class RendererExtensions
{
public static bool IsVisibleFrom( this Renderer renderer, Camera camera )
{
Plane[] planes = GeometryUtility.CalculateFrustumPlanes( camera );
return GeometryUtility.TestPlanesAABB( planes, renderer.bounds );
}
}
@arxae
arxae / DispatchTables.cs
Last active December 26, 2015 14:49
Dispatch tables
// Regular dispatch table
Dictionary<string, Action> dispatch = new Dictionary<string, Action>();
dispatch["help"] = new Action(() => Console.WriteLine("Hello :3"));
dispatch["dosomething"] = new Action(() =>
{
Console.WriteLine("Do Something else");
});
dispatch["help"]();
@arxae
arxae / ArxOrthoShadows.shader
Created August 19, 2014 10:20
Dynamic shadows in Unity pro using an orthogonal camera. Use as shader for all objects that need to cast and/or receive shadows.
Shader "ArxOrthoShadows" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
_BumpMap ("Normalmap", 2D) = "bump" {}
_Detail ("Detail (RGB)", 2D) = "gray" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 400
@arxae
arxae / CameraFollow.cs
Created August 22, 2014 10:53
[Unity] Smoothly follows the target. Attach to the camera
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform Target;
public float Damping = 1f;
public float LookAheadFactor = 3f;
public float LookAheadReturnSpeed = 0.5f;
public float LookAheadMoveTreshold = 0.1f;
@arxae
arxae / Singleton.cs
Last active December 18, 2015 07:27
Generic singleton pattern
// Usage: Singletone<classtype>.Instance
public sealed class Singleton<T> where T : new()
{
public static T Instance => Inner.InnerInstance;
private Singleton() { }
private class Inner
{
internal static T InnerInstance = new T();
@arxae
arxae / archive.sh
Created July 6, 2016 03:24
Archives youtube channels.
#!/bin/sh
YOUTUBEDL='/usr/local/bin/youtube-dl' # Absolute path to youtube-dl executable
ARCHIVE='~/youtube_archive' # Absolute path to archive
$YOUTUBEDL -U
archive () {
mkdir -p "$ARCHIVE/$1"
cd "$ARCHIVE/$1"
@arxae
arxae / BitmapEx.cs
Created July 17, 2016 20:18
Change color of bitmap
public static class BitmapExt
{
public static void ChangeColour(this Bitmap bmp, byte inColourR, byte inColourG, byte inColourB, byte outColourR, byte outColourG, byte outColourB)
{
// Specify a pixel format.
PixelFormat pxf = PixelFormat.Format24bppRgb;
// Lock the bitmap's bits.
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
BitmapData bmpData =
@arxae
arxae / fossil-git.txt
Created August 2, 2016 06:55
Fossil <-> Git
Fossil -> Git
git init new-repo
cd new-repo
fossil export --git ../repo.fossil | git fast-import
git merge trunk
git branch -d trunk
Git -> Fossil
cd git-repo
@arxae
arxae / TaskQueueRunner.cs
Created December 26, 2016 03:23
Loops over a list to keep tasks running with a max ammount
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using System.Threading;
namespace TestProject
{
class Program
{