Skip to content

Instantly share code, notes, and snippets.

View mahan's full-sized avatar

Mattias Hansson mahan

  • KGH Customs Services
  • sweden
View GitHub Profile
@mahan
mahan / GuidGenerator.cs
Created July 11, 2019 14:49 — forked from nberardi/GuidGenerator.cs
TimeUUID Generator for .NET
using System;
namespace FluentCassandra
{
/// <summary>
/// Used for generating UUID based on RFC 4122.
/// </summary>
/// <seealso href="http://www.ietf.org/rfc/rfc4122.txt">RFC 4122 - A Universally Unique IDentifier (UUID) URN Namespace</seealso>
public static partial class GuidGenerator
{
function RotateSprite(s as integer, ang as integer)
if (ang < 0) or (ang >= 360) then ang = mod(abs(ang), 360)
if not (mod(ang, 90) = 0) then ang = Trunc(ang / 90) * 90
cx as integer
cy as integer
select ang
case 0
@mahan
mahan / imagemix.pb
Created July 18, 2016 17:55
Demo: Mixing two images in PureBasic (assumes 2 128x128 textures)
UsePNGImageDecoder()
UsePNGImageEncoder()
Global Dim imageColors.i(1, 128, 128)
Procedure main()
LoadImage(0, "clay_cut_128px_ta.png")
LoadImage(1, "grass_cut_128_ta.png")
unit ufMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
inpath = r"C:\develop\taric_work\taric_XML_v2\tot"
midpath = inpath + r".uncrypt"
outpath = inpath + r".unpack"
from os import listdir, path, makedirs, remove, rename
from os.path import isfile, join
#Algorithm taken from here (+ cleaned + simplified + commented):
#https://chinmaylokesh.wordpress.com/2011/03/08/algorithm-to-find-all-distinct-sums-using-numbers-from-a-list-that-add-up-to-a-specified-sum/
def tsum(currentIndex,total):
if total==SUM :
s = ""
for i in xrange(0,L):
if record[i]:
s = s + str(NUMBERS[i]) + ", "
print s[0:-2] #remove last comma from result
getPixels = require 'get-pixels'
decimalToHexString = (number) ->
if number < 0
number = 0xFFFFFFFF + number + 1
return number.toString(16).toUpperCase()
getPixels "16x16test2.png", (err, pixels) ->
if err
console.log "Bad image path"
@mahan
mahan / gist:6256149
Last active January 7, 2021 16:19
Atomic boolean for golang
/* Atomic boolean for golang
A process-atomic boolean that can be used for signaling between goroutines.
Default value = false. (nil structure)
*/
package main
import "sync/atomic"
@mahan
mahan / arrtest.c
Created September 2, 2012 13:54
Optimized count of set bits in an array in C (written in XCode 4.4)
//
// main.c
// arrtest
//
// Created by Mattias (hz) Hansson on 9/2/12.
// Public Domain. Credits/Bugfixes welcome.
//
#include <stdio.h>
#include <stdlib.h>