Skip to content

Instantly share code, notes, and snippets.

public static Vector4 HSVToRGB(float hue, float saturation, float value, float alpha)
{
Func<float, float> helper = (x) =>
{
float lowerBound = value * (1 - saturation);
float delta = value - lowerBound;
while (x < 0) x += 360;
x = x % 360;
return lowerBound + (float)((Math.Floor(x / 180) * value) + Math.Floor(((Math.Floor(x / 60) % 3) / 2)) * (x % 60) * (delta / 60F) * Math.Pow(-1, Math.Floor(x / 180)));
};
static void Main(string[] args)
{
var rand = new Random();
int success = 0;
for (int i = 0; i < 100000; ++i)
{
var arr = Shuffle(new List<int> { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 });
int sum = 0;
for (int j = 0; j < 3; ++j)
public static void PackRectanglesModify(List<PackedRectangle> rectangles)
{
rectangles.Sort
(
Comparing.CreateComparer<PackedRectangle, double>
(
rect => rect.Rectangle.Size.X * rect.Rectangle.Size.Y
)
);
rectangles.Reverse();
type IRectangle =
abstract member X : double with get, set
abstract member Y : double with get, set
abstract member Width : double
abstract member Height : double
abstract member Id : int
type internal Spot(x: double, y: double, width: double, height: double) =
member this.x = x
member this.y = y
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
private static Form form;
private static Thread thread;
private static event Action showRequest;
public static void OpenForm()
{
if (thread == null)
{
thread = new Thread(() =>
{
// ==UserScript==
// @name Stop gif animations on escape
// @namespace http://github.com/johan/
// @description Implements the "stop gif animations on hitting the escape key" feature that all browsers except Safari and Google Chrome have had since forever. Now also for Google Chrome!
// ==/UserScript==
document.addEventListener('keydown', freeze_gifs_on_escape, true);
function freeze_gifs_on_escape(e) {
if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
@LukaHorvat
LukaHorvat / packing
Created February 11, 2014 11:19
Rectangle packing in F#
namespace Firefly2.Functional.RectanglePacking
type IRectangle =
abstract member X : double with get, set
abstract member Y : double with get, set
abstract member Width : double
abstract member Height : double
abstract member Id : int
type internal Spot(x: double, y: double, width: double, height: double) =
{-# LANGUAGE PatternSynonyms #-}
module Reduction where
import Data.Maybe
import Function
pattern NumFrac n d = Number n :/: Number d
isConst :: Expression -> Bool
isConst (Number _) = True