Skip to content

Instantly share code, notes, and snippets.

View ssube's full-sized avatar

Sean Sube ssube

View GitHub Profile
@ssube
ssube / LayerImpl.java
Created July 21, 2014 15:09
Java software shader, with int optimizations
package com.stackoverflow.questions;
public class LayerImpl implements LayerProcessor {
@Override
public int apply(final int[][] data, final int x, final int y) {
int[] col = data[x];
int accumulator = col[y] * 2
+ data[x-1][y]
+ data[x+1][y]
+ col[y-1]
package com.stackoverflow.questions;
public class BlurShader implements Shader {
@Override
public int apply(final int[] d, final int s, final int x, final int y) {
final int p = s * y + x;
final int a = d[p] * 2
+ d[p - 1]
+ d[p + 1]
+ d[p - s]
# VM invoker: /usr/java/jdk1.8.0_11/jre/bin/java
# VM options: <none>
# Warmup: 20 iterations, 1 s each# Measurement: 20 iterations, 1 s each
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: com.stackoverflow.questions.ShaderBench.testProcessProc
# Run progress: 0.00% complete, ETA 00:20:00
# Fork: 1 of 10
# Preparing profilers: perfasm
# VM invoker: /usr/java/jdk1.8.0_11/jre/bin/java
# VM options: <none>
# Warmup: 20 iterations, 1 s each
# Measurement: 20 iterations, 1 s each
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: com.stackoverflow.questions.ShaderBench.testProcessProc
Forking 10 times using command: [perf, record, -F 1000, -e cycles,instructions, -o/tmp/jmh4344991220022041242perfbin, /usr/java/jdk1.8.0_11/jre/bin/java, -XX:+UnlockDiagnosticVMOptions, -XX:+TraceClassLoading, -XX:+LogCompilation, -XX:LogFile=/tmp/jmh6423091247981809078hslog, -XX:+PrintAssembly, -XX:+PrintCompilation, -XX:+PrintInlining, -XX:CompileCommandFile=/tmp/jmh3299179036504755608compilecommand, -cp, benchmarks.jar, org.openjdk.jmh.runner.ForkedMain, 127.0.0.1, 52178]
# Run progress: 0.00% complete, ETA 00:20:00
@ssube
ssube / flat_complex_call
Last active August 29, 2015 14:05
flatscript
val add = (a, b) -> {
a + b;
};
val sub = (a, b) -> {
a - b;
};
val square = (a) -> {
a * a;
};
val cube = (a) -> {
function EXT_COLOR () { echo -ne "\e[38;5;$1m"; }
function CLOSE_COLOR () { echo -ne '\e[m'; }
export CLICOLOR=1
export PS1="\[`EXT_COLOR 187`\]\u@\h\[`CLOSE_COLOR`\]\[`EXT_COLOR 174`\] \w \$ \[`CLOSE_COLOR`\] > "
export LS_COLORS='di=38;5;108:fi=00:*svn-commit.tmp=31:ln=38;5;116:ex=38;5;186:*java=38;5;94:*groovy=38;5;95'
function cds() {
C=0;
to find the linearly interpolated value of (x + 0.4, y + 0.7)
given the values at (x, y), (x, y+1), (x+1, y), and (x+1, y+1)
let x1 = val(x, y) * 0.4 + (val(x, y+1) * 0.6)
let x2 = val(x+1, y) * 0.4 + (val(x+1, y+1) * 0.6)
the final value is (x1 * 0.7 + (x2 * 0.3))
generalized:
# Change the external_url to the address your users will type in their browser
external_url 'http://code.domain.com'
git_data_dir '/opt/git/'
default_can_create_group false
username_changing_enabled false
signup_enabled false
gitlab_rails['extra_google_analystics_id'] = 'id'
# LDAP Auth
gitlab_rails['ldap_enabled'] = true
import Shader = require("./Shader");
export = BlurShader;
class BlurShader implements Shader {
apply(d:number[], o:number[], s:number, xmin:number, xmax:number, ymin:number, ymax:number) {
for (var y:number = ymin; y < ymax; ++y) {
for (var x:number = xmin; x < xmax; ++x) {
var p:number = y * s + x;
var a:number = d[p] * 2
var BlurShader = (function () {
function BlurShader() {
}
BlurShader.prototype.apply = function (d, o, s, xmin, xmax, ymin, ymax) {
for (var y = ymin; y < ymax; ++y) {
for (var x = xmin; x < xmax; ++x) {
var p = y * s + x;
var a = d[p] * 2 + d[p - 1] + d[p + 1] + d[p - s] + d[p + s];
a = (1000 * (a + 500)) / 6000;