Skip to content

Instantly share code, notes, and snippets.

View audinue's full-sized avatar

Audi Nugraha audinue

  • Surabaya, Jawa Timur, Indonesia
View GitHub Profile
@audinue
audinue / object-map.js
Last active October 30, 2020 02:35
Iterable safe plain JavaScript object as map.
function objectMap () {
return Object.defineProperty(Object.create(null), Symbol.iterator, {
configurable: true, // This descriptor is inspired by Map.prototype[Symbol.iterator]
writable: true,
value: function* () {
for (const key in this) {
yield [key, this[key]]
}
}
})
@audinue
audinue / Container.cs
Created August 9, 2017 07:19
An automatic dependency injection container.
using System;
using System.Collections.Generic;
using System.Linq;
public sealed class Container
{
private Dictionary<Type, Type> concreteTypes = new Dictionary<Type, Type>();
private Dictionary<Type, object> objects = new Dictionary<Type, object>();
@draegtun
draegtun / simple-lambda-example.reb
Last active September 6, 2018 09:38
Very simple anonymous lambda generator in Rebol
>> double: lambda [? * 2]
>> double 2
== 4
>> double: lambda [? + ?]
>> double 4
== 8
>> add2: lambda [?1 + ?2]
>> add2 2 4
@dmajda
dmajda / indentation-based.pegjs
Created November 27, 2015 15:00
Simple intentation-based language PEG.js grammar
/*
* Simple Intentation-Based Language PEG.js Grammar
* ================================================
*
* Describes a simple indentation-based language. A program in this language is
* a possibly empty list of the following statements:
*
* * S (simple)
*
* Consists of the letter "S".
@XProger
XProger / min_ogl.dpr
Last active June 23, 2022 08:16
Delphi minimal OpenGL application
program min_ogl;
uses
Windows, OpenGL;
var
pfd : TPixelFormatDescriptor;
DC : HDC;
begin
// Creating window
@irazasyed
irazasyed / spintax.php
Last active February 21, 2024 17:29
PHP: Text Spinner Class - Nested spinning supported.
<?PHP
/**
* Spintax - A helper class to process Spintax strings.
*/
class Spintax
{
/**
* Set seed to make the spinner predictable.
*/
@dmajda
dmajda / gist:7688943
Created November 28, 2013 08:49
Simple PEG.js grammar to parse a markup language with nested elements (like XML)
Content =
(Element / Text)*
Element =
startTag:StartTag content:Content endTag:EndTag {
if (startTag != endTag) {
throw new Error(
"Expected </" + startTag + "> but </" + endTag + "> found."
);
}
IMPORTANT
Please duplicate this radar for a Safari fix!
This will clean up a 50-line workaround.
rdar://22376037 (https://openradar.appspot.com/radar?id=4965070979203072)
//////////////////////////////////////////////////////////////////////////////
(Now available as a standalone repo.)
@mjackson
mjackson / color-conversion-algorithms.js
Last active April 14, 2024 08:46
RGB, HSV, and HSL color conversion algorithms in JavaScript
/**
* Converts an RGB color value to HSL. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes r, g, and b are contained in the set [0, 255] and
* returns h, s, and l in the set [0, 1].
*
* @param Number r The red color value
* @param Number g The green color value
* @param Number b The blue color value
* @return Array The HSL representation
@riyadparvez
riyadparvez / Winform Flickering.cs
Created December 31, 2012 12:58
Add this code snippet into your form or control class to stop flickering in winform
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}