Skip to content

Instantly share code, notes, and snippets.

@kevinswiber
kevinswiber / Program.cs
Created November 23, 2011 23:05
Passing messages between Node.js and C#.
using System;
using System.Text;
namespace NodeIPC
{
class Program
{
static void Main(string[] args)
{
var input = Console.OpenStandardInput();
@gregerhalltorp
gregerhalltorp / gist:1853953
Created February 17, 2012 15:06
Custom type converter for converting between MongoDB.Bson.ObjectId and string
public class ObjectIdConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context,
Type sourceType)
{
if (sourceType == typeof(string))
return true;
return base.CanConvertFrom(context, sourceType);
}
@stefanocudini
stefanocudini / randcolorhue.js
Created March 25, 2012 13:04
generate random color with same colore tone
function randcolorhue(rgb) { //generate random color with same colore tone
var hsl = rgb2hsl(rgb);
var newhsl = [ Math.min(hsl[0]*minmaxrandom(0.95,1.05),1), hsl[1]*minmaxrandom(0.7,1), Math.min(hsl[2]*minmaxrandom(0.8,1.2),1) ];
//stessa tonalita'
return hsl2rgb(newhsl);
}
function minmaxrandom(min, max) //genera numero casuale compreso in un range di valori
{
return Math.random() * (max - min) + min;
@sloria
sloria / bobp-python.md
Last active July 24, 2024 02:53
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@dhont
dhont / gist:8298537
Last active November 26, 2019 23:39
A basic implementation of a thread safe List. Is particularly useful when combined with GetEnumerator() and provides an Remove(T) implementation.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Tinmar.Domain.Common
{
public sealed class ConcurrentList<T> : IList<T>
{
private readonly IList<T> _items = new List<T>();
@rickbeerendonk
rickbeerendonk / uuid.cs
Created August 10, 2014 00:07
Java's Universally Unique Identifier (UUID) implementation in C#
// Copyright © 2014 Rick Beerendonk. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
@chris-rock
chris-rock / crypto-buffer.js
Last active May 30, 2024 15:57
Encrypt and decrypt buffers in nodejs
// Part of https://github.com/chris-rock/node-crypto-examples
var crypto = require('crypto'),
algorithm = 'aes-256-ctr',
password = 'd6F3Efeq';
function encrypt(buffer){
var cipher = crypto.createCipher(algorithm,password)
var crypted = Buffer.concat([cipher.update(buffer),cipher.final()]);
return crypted;
@myusuf3
myusuf3 / delete_git_submodule.md
Created November 3, 2014 17:36
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
public class ConcurrentList<T> : IList<T>, IDisposable
{
private ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
private int _count = 0;
public int Count
{
get
{
_lock.EnterReadLock();
@mfuerstenau
mfuerstenau / zigzag-encoding.README
Last active July 1, 2024 17:19
ZigZag encoding/decoding explained
ZigZag-Encoding
---------------
Maps negative values to positive values while going back and
forth (0 = 0, -1 = 1, 1 = 2, -2 = 3, 2 = 4, -3 = 5, 3 = 6 ...)
(i >> bitlength-1) ^ (i << 1)
with "i" being the number to be encoded, "^" being
XOR-operation and ">>" would be arithemtic shifting-operation