Skip to content

Instantly share code, notes, and snippets.

@macromaniac
macromaniac / BitmapBytes.cs
Last active February 7, 2024 19:57
Low level C# Bitmap Serializer. Surprisingly 5x faster than the commonly used .net BitmapData (tested on 100x100 images). Mostly for when you want finer tune control over your bitmaps than .net gives you.
using System;
public class BitmapBytes
{
/// <summary>
/// Converts RGBA bytes into an RGBA Bitmap.
/// Pixels go left to right, bottom to top.
/// Can write to file with, e.g:
/// File.WriteAllBytes("example.bmp", BitmapBytes.FromRGBABytes(imageData, width));
/// </summary>
@macromaniac
macromaniac / regression.py
Created September 17, 2016 18:47
simple linear regression example using keras
import numpy as np
from keras.layers import Dense, Input
from keras.models import Model
x = Input((1,))
y = Dense(1, activation ='linear')(x)
m = Model(x,y)
m.compile(loss = 'mse', optimizer='sgd')
_x = np.linspace(1,2, num = 1e3)
@macromaniac
macromaniac / SwipeGestures.cs
Created November 18, 2015 17:48
Simple way to detect swipes in unity. Reference the monobehaviour and you're done.
using UnityEngine;
using System.Collections.Generic;
using System;
public enum SwipeGesture { SwipeUp, SwipeDown, SwipeLeft, SwipeRight, None };
/// <summary>
/// Simplest usage:
///
/// public SwipeGestures Gestures; // Reference to MonoBehaviour
@macromaniac
macromaniac / webpack.config.js
Last active October 27, 2015 13:15
Typescript Webpack with Visual Studio setup, launch via NPM
// SIMPLE VISUAL STUDIO WEBPACK CONFIG
// Auto reloading, Sourcemaps, es6 modules loading, uses visual studio to compile the typescript
// required DevDependencies:
// webpack
// source-map-loader
// browser-sync
// browser-sync-webpack-plugin
// babel-loader
//
// in tsconfig enable sourcemaps and set es6 to true
@macromaniac
macromaniac / applyt4transform.bat
Created April 16, 2015 22:48
Change the extension to equal whatever extension you're using, this file applies the t4 transformation (you can use it in the pre build events or post build events). If it is exists in your bin folder the command to run is "applyt4transform.bat ..\..".
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
:: set the working dir (default to current dir)
set wdir=%cd%
if not (%1)==() set wdir=%1
:: set the file extension (default to vb)
set extension=d.ts
if not (%2)==() set extension=%2
@macromaniac
macromaniac / XHR.ts
Last active November 3, 2019 23:19
simple typescript xhr using promises
module XHR {
export class Header {
header: string;
data: string;
constructor(header: string, data: string) {
this.header = header;
this.data = data;
}
}