Skip to content

Instantly share code, notes, and snippets.

View avanderw's full-sized avatar

Andrew van der Westhuizen avanderw

View GitHub Profile
@avanderw
avanderw / image-grayscale
Last active February 22, 2024 06:15
The following color matrix filter will grayscale an image.
private const matrix:Array = [
0.3, 0.59, 0.11, 0, 0,
0.3, 0.59, 0.11, 0, 0,
0.3, 0.59, 0.11, 0, 0,
0, 0, 0, 1, 0];
private const zero:Point = new Point();
grayscale.bitmapData.applyFilter(image.bitmapData, image.getRect(image), zero, new ColorMatrixFilter(matrix));
@avanderw
avanderw / water-reflection-effect
Created July 26, 2013 08:37
This effect will reflect a display object and apply a displacement map filter which animated each frame. The result is what looks like something reflected on the surface of water. This is a response to a request on my site, www.avanderw.co.za, for a commented and compilable version of this effect. To run this file, include it in your editor of c…
package net.avdw
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.DisplacementMapFilter;
import flash.filters.DisplacementMapFilterMode;
import flash.geom.Matrix;
@avanderw
avanderw / MouseMover.java
Last active June 1, 2021 16:25
Moves the mouse every 10 minutes to a random location on the screen. Great for keeping the screen active when you are not active.
package net.avdw.hangman;
import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
import org.jnativehook.keyboard.NativeKeyEvent;
import org.jnativehook.keyboard.NativeKeyListener;
import java.awt.*;
import java.util.Random;
import java.util.concurrent.TimeUnit;
@avanderw
avanderw / Vector2D.java
Last active December 2, 2020 08:35
Mutable 2D Vector
package net.avdw;
/**
* Single class mutable 2D vector.
*
* @version 2020-12-02 Started versioning
*/
public class Vector2D {
protected static final Double EPSILON = 0.0000001;
@avanderw
avanderw / Vector2DConst.java
Created December 2, 2020 08:36
Single class immutable 2D vector.
package net.avdw;
/**
* Single class immutable 2D vector.
*
* @version 2020-12-02 Copied from Vector2D
*/
public class Vector2DConst {
protected static final Double EPSILON = 0.0000001;
@avanderw
avanderw / java8-one-liners-for-statistical-properties.md
Created May 14, 2021 08:54 — forked from asela38/java8-one-liners-for-statistical-properties.md
Java 8 One liners for statistical properties : Mean, Mode, Median(Q2), Q1, Q2, Variance, Standard Deviation

While working on a Hacker Rank Problem I wrote few one lines using java stream to find mean, median, mode, Q1, Q3, variance and standard deviation. Thought to share since it's quite interesting.

        // mean
        double mean = list.stream().mapToInt(Integer::intValue).average().getAsDouble();
        System.out.println(mean);
        
        // mode - create count map using group by and sorted with custom comparator to give minimum from competing probable mode values
        Integer mode = list.stream()
                .collect(Collectors.groupingBy(i -> i, () -> new TreeMap<Integer, Long>(), Collectors.counting()))
@avanderw
avanderw / .minttyrc
Last active December 16, 2021 11:18 — forked from inkychris/.minttyrc
Git Bash Theme - Monokai
Font=Consolas
FontHeight=12
FontSmoothing=full
AllowBlinking=yes
Columns=128
Rows=32
PgUpDnScroll=yes
ThemeFile=
Transparency=
BoldAsFont=no