Skip to content

Instantly share code, notes, and snippets.

View JimBobSquarePants's full-sized avatar
💭
(•_•) ( •_•)>⌐■-■ (⌐■_■)

James Jackson-South JimBobSquarePants

💭
(•_•) ( •_•)>⌐■-■ (⌐■_■)
View GitHub Profile
@JimBobSquarePants
JimBobSquarePants / datagrabber.js
Last active August 5, 2018 21:12
API for getting data from an elements data-attributes.
const DataGrabber = w => {
const dataMap = new WeakMap();
const rdashAlpha = /-([a-z])/g;
const fcamelCase = (all, letter) => letter.toUpperCase();
/**
* Returns a transformed string in camel case format
* @param {string} value The string to alter
* @returns {string}
@JimBobSquarePants
JimBobSquarePants / TaskTest.cs
Created July 10, 2018 08:22
Attempt at demoing returning only completed tasks from a collection.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TaskTest
{
class Program
{
private static Random r = new Random();
@JimBobSquarePants
JimBobSquarePants / DominantColor.cs
Created June 7, 2018 11:58
Get dominant color from an image using ImageSharp and ImageProcessor
// ##### ImageSharp #####
using (var image = Image.Load<Rgb24>(inPath))
{
image.Mutate(
x => x
// Scale the image down preserving the aspect ratio. This will speed up quantization.
// We use nearest neighbor as it will be the fastest approach.
.Resize(new ResizeOptions() { Sampler = KnownResamplers.NearestNeighbor, Size = new Size(100, 0) })
@JimBobSquarePants
JimBobSquarePants / genesis_public_key
Created February 23, 2018 13:29
genesis_public_key
04cfbd9a24bec73307bf73ad60214a580bb852e6fed5c8f839f7d4ab8c412e0530c2011f1c5486ede44289c6e8c33dd098494f5afbdd7ac5cf32942303602a9381
@JimBobSquarePants
JimBobSquarePants / MatrixNxN.cs
Created February 13, 2018 13:57
Attempt at a fast dense array.
/// <summary>
/// Represents a dense array of NxN dimensions.
/// </summary>
/// <typeparam name="T">The type of elements in the array.</typeparam>
public struct MatrixNxN<T>
{
/// <summary>
/// The 1D representation of the 2D array.
/// </summary>
public readonly T[] Data;
@JimBobSquarePants
JimBobSquarePants / BayerMatrixGenerator.cs
Created February 1, 2018 00:37
Algorithm for generating Bayer Matrices of arbitrary dimensions. See https://en.wikipedia.org/wiki/Ordered_dithering
void Main()
{
// Compute the Bayer matrix for the given order.
// 2^1 = 2x2 matrice
// 2^2 = 4x4 matrice
// 2^3 = 8x8 matrice
ComputeBayer(1);
ComputeBayer(2);
ComputeBayer(3);
}
@JimBobSquarePants
JimBobSquarePants / swiper.html
Last active September 27, 2017 07:28
Demo for consuming the swiper code.
<script src="swiper.js"></script>
<script>
let swiper = new Swiper(".target");
swiper.onSwipeMove(e => { /* Can track delta here */ })
.onSwipeEnd(e => {
swiper.elements.forEach(function (element) {
element.innerHTML = "<br>Direction: " + e.detail.direction
+ "<br>Distance: x = " + e.detail.delta.x + ",y = " + e.detail.delta.y
+ "<br>Duration: " + e.detail.duration + "ms";
@JimBobSquarePants
JimBobSquarePants / LocalFunctions.cs
Created June 21, 2017 14:20
Demoing local assignment of local functions
void Main()
{
string m;
void DoSomething(int i)
{
m = "DoSomething";
m.Dump();
(i + 1).Dump();
}
BenchmarkDotNet=v0.10.1, OS=Microsoft Windows NT 6.2.9200.0
Processor=Intel(R) Core(TM) i7-6600U CPU 2.60GHz, ProcessorCount=4
Frequency=2742185 Hz, Resolution=364.6727 ns, Timer=TSC
  [Host]     : Clr 4.0.30319.42000, 64bit RyuJIT-v4.7.2046.0
  DefaultJob : Clr 4.0.30319.42000, 64bit RyuJIT-v4.7.2046.0
Method Mean StdDev Scaled Scaled-StdDev Allocated
'System.Drawing Resize' 61.8849 ms 1.5651 ms 1.00 0.00 512 B
@JimBobSquarePants
JimBobSquarePants / YCbCrToRgbTables.cs
Created April 24, 2017 23:19
LUT Tables for YCbCr -> Rgb conversion method
// <copyright file="YCbCrToRgbTables.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats.Jpeg.Components.Decoder
{
using System.Runtime.CompilerServices;
using ImageSharp.PixelFormats;