Skip to content

Instantly share code, notes, and snippets.

@gomson
gomson / SpyInstanciations.java
Created June 24, 2018 14:33 — forked from superbob/SpyInstanciations.java
Simple but powerfull Java TimeSpy. It wraps up a java method call in a spy class (method proxy) and records total elapsed time in successive calls. 1) [SpyInstanciations.java] Create an anonymous class extending TimeSpy which defines the run() method and returns something. 2) [SpyRuns.java] Run run(), instead of "your" method 3) [SpyResult.java]…
TimeSpy<Boolean> rsSpy = new TimeSpy<Boolean>() {
protected Boolean run() throws Exception {
return resultSet.next();
}
};
TimeSpy<Boolean> statementSpy = new TimeSpy<Boolean>() {
protected Boolean run() throws Exception {
return statement.execute();
}
@gomson
gomson / ByteUtil.java
Created June 24, 2018 14:33 — forked from superbob/ByteUtil.java
byte array initialization from a int/long/short literal => byte[] array = toBytes(0x01020304);
package com.example.util;
import java.nio.ByteBuffer;
public final class ByteUtil {
private ByteUtil() {
}
/**
@gomson
gomson / cpp_utf8_utf16.cpp
Created February 5, 2018 09:36 — forked from gchudnov/cpp_utf8_utf16.cpp
C++ string conversion UTF8 <-> UTF16
#include <string>
#include <locale>
#include <codecvt>
//UTF-8 to UTF-16
std::string source;
//...
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
std::u16string dest = convert.from_bytes(source);
/* @flow */
// Implement SPECTRE on DAG
// WIP: Not tested and not runnable yet
import uuid from 'uuid'
import sortBy from 'lodash.sortby'
import SHA256 from 'crypto-js/sha256'
import immer from 'immer'
/*
The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
/*
This software is released under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
@gomson
gomson / mdct_via_fft.m
Created October 3, 2017 09:36 — forked from rygorous/mdct_via_fft.m
MDCT via FFT
function y = mdct_via_fft(x)
% This was edited together from multiple fns in the original source
% for this gist, I might well have introduced errors along the way.
% Rows of x correspond to samples
nrows = size(x,1);
if mod(nrows,4) ~= 0 || nrows<8
error('Number of rows must be multiple of 4 and at least 8.');
end
nr4 = nrows/4;
@gomson
gomson / PImage.cs
Created September 7, 2017 09:45 — forked from KelsonBall/PImage.cs
using System;
using System.IO;
using ImageSharp;
using ImageSharp.Processing;
using SixLabors.Primitives;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using static OpenTK.DisplayDevice;
using Processing.OpenTk.Core.Extensions;
@gomson
gomson / PImage.cs
Created September 7, 2017 09:44 — forked from KelsonBall/PImage.cs
using System;
using System.IO;
using ImageSharp;
using ImageSharp.Processing;
using SixLabors.Primitives;
using OpenTK.Graphics.OpenGL;
using Processing.OpenTk.Core.Extensions;
namespace Processing.OpenTk.Core.Textures
{