Skip to content

Instantly share code, notes, and snippets.

@soywiz
soywiz / getSubversion17MaxRevisionFromFolder
Created October 5, 2011 23:30
Obtain the max revision from a Subversion 1.7 repository
<?php
function getSubversion17MaxRevisionFromFolder($checkoutFolderPath) {
$db = new PDO('sqlite:' . realpath($checkoutFolderPath) . '/.svn/wc.db');
foreach ($db->query('SELECT MAX(revision) FROM NODES;') as $row) return $row[0];
return false;
}
@soywiz
soywiz / haxe_fast_constant16_integer_divide.hx
Created September 1, 2012 10:12
HAXE: Divide an integer expression by an integer constant (it converts the division into a multiplication and a shift)
class MathEx {
/**
* Divide the first integer expression by the second constant integer value.
* It will just work with numerator being and unsigned short value (0x0000-0xFFFF)
*
* @param numerator Unsigned short numerator value
* @param denominator Constant denominator value
* @return
*/
@:macro static public function fastUintConstDiv16(numerator:Expr, denominator:Int):Expr {
public class TransitionBlendGpu
{
GraphicsDevice GraphicsDevice;
SpriteBatch SpriteBatch;
BlendState BlendAlpha1;
BlendState BlendAlphaAdd;
BlendState BlendAlphaSub;
Texture2D DummyTexture;
public TransitionBlendGpu(GraphicsDevice GraphicsDevice)
public struct RGBA
{
public byte R, G, B, A;
}
class MyClass
{
static public RGBA[] ColorPixels = new RGBA[800 * 480];
static public byte[] Lookup = new byte[256];
@soywiz
soywiz / gist:3f9569fbcddae1fed1d0
Created September 2, 2014 20:13
haxe macro swap
var a = 1;
var b = 2;
swap(a, b);
trace('$a, $b');
macro static public function swap(a:Expr, b:Expr) {
return macro {
var temp = $a;
$a = $b;
$b = temp;
@soywiz
soywiz / Haxe: Calculate distance-map in linear time
Created January 26, 2015 11:04
Haxe: Calculate distance-map in linear time
package ;
import haxe.Log;
import haxe.ds.Vector;
import haxe.io.Bytes;
class Fixer {
static public function main() {
var m = Matrix.fromRows([
[0, 0, 0, 1, 0, 1, 1],
[0, 0, 0, 1, 0, 0, 0],
@soywiz
soywiz / gist:0a1381aa36b1e6711e0d
Last active August 29, 2015 14:14
fix black transparent alpha without premultiplied alpha
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <float.h>
#include <gd.h>
#define max(a, b) ((a > b) ? (a) : (b))
unsigned int nextpot(unsigned int v) {
v--;
@soywiz
soywiz / lljvm zlib make error
Created May 27, 2016 00:24
lljvm zlib make error
root@d49d7666f4b7:/usr/local/lib/lljvm/demo/zlib# make
cd ../../thirdparty && make zlib
make[1]: Entering directory `/usr/local/lib/lljvm-bin-linux-i386-0.2/thirdparty'
wget -c http://zlib.net/fossils/zlib-1.2.3.tar.gz -O zlib-1.2.3.tar.gz.part
--2016-05-27 00:22:48-- http://zlib.net/fossils/zlib-1.2.3.tar.gz
Resolving zlib.net (zlib.net)... 69.73.132.10
Connecting to zlib.net (zlib.net)|69.73.132.10|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 496597 (485K) [application/x-gzip]
Saving to: 'zlib-1.2.3.tar.gz.part'
// More examples here: https://github.com/kotlin-es/coroutine-examples/blob/master/src/example-generator.kt
fun main(args: Array<String>) {
//val infiniteList = generate<Int> { for (n in 0 .. 3) yield(n) }
val infiniteList = generate<Int> { for (n in 0 .. Int.MAX_VALUE) yield(n) }
for (i in infiniteList.lazyFilter { it % 2 == 0 }) {
//for (i in infiniteList) {
println(i)
}
// More examples here: https://github.com/kotlin-es/coroutine-examples/blob/master/src/example-await-async.kt
import java.net.URL
import java.util.*
import java.util.concurrent.ConcurrentLinkedDeque
fun main(args: Array<String>) {
EventLoop.main {
async<String> {
val secondsToWait = 3