Skip to content

Instantly share code, notes, and snippets.

View OakNinja's full-sized avatar
:octocat:
Poking around like a 🦑

Esse Woods OakNinja

:octocat:
Poking around like a 🦑
View GitHub Profile
@OakNinja
OakNinja / BubbleSort.java
Created November 21, 2019 21:43
A more readable bubble sort.
public class BubbleSort {
public static void main(String[] args) {
int[] numbers = {544, 1, 12, 7, 449, 99, 66, 32, 43, 17, 19, 999};
sort(numbers);
}
public static void sort(int[] numbers) {
boolean sortAgain = false;
@OakNinja
OakNinja / dpiscale.cs
Created May 9, 2019 18:59
WPF, Forms: Get the scaling/DPI scale factor on the device currently the application without the need of any UI elements using reflection. Useful for GDI stuff where you want to predict the composition.
public static class DpiScale
{
private static readonly float WindowsDefaultDpi = 96.0f;
private enum Axis {X, Y};
private static float GetScaleForAxis(Axis axis)
{
var axisProperty = axis == Axis.X ? "DpiX" : "Dpi";
var dpiProperty = typeof(SystemParameters).GetProperty(axisProperty, BindingFlags.NonPublic | BindingFlags.Static);
var deviceDpi = (int)dpiProperty.GetValue(null, null);
@OakNinja
OakNinja / pre-commit
Last active February 16, 2016 12:02
Pre-commit-hook that runs static analysis on staged python and js files. On errors, each error is printed and the commit is aborted .
#!/bin/sh
echo '### Commit if static analysis pass'
IFS=$'\n'
staged_files=($(git diff --staged --name-only --no-color))
if [ ${#staged_files[@]} -eq 0 ]; then
echo "### No staged files, exiting"
exit 1
else
echo '### Running static analysis on staged files'
@OakNinja
OakNinja / svtplay_subscribe.py
Last active September 20, 2015 21:58
Download new episodes based on keywords from SVT play
import os
import svtplay_dl
import re
import feedparser
__author__ = 'oakninja'
def lines(file_name):
home = os.path.expanduser("~")