Skip to content

Instantly share code, notes, and snippets.

View nberardi's full-sized avatar
😀

Nick Berardi nberardi

😀
View GitHub Profile
@nberardi
nberardi / BigDecimal.cs
Created May 12, 2012 15:17
BigDecimal type in .NET
using System;
using System.Linq;
namespace System.Numerics
{
public struct BigDecimal : IConvertible, IFormattable, IComparable, IComparable<BigDecimal>, IEquatable<BigDecimal>
{
public static readonly BigDecimal MinusOne = new BigDecimal(BigInteger.MinusOne, 0);
public static readonly BigDecimal Zero = new BigDecimal(BigInteger.Zero, 0);
public static readonly BigDecimal One = new BigDecimal(BigInteger.One, 0);
@nberardi
nberardi / GuidGenerator.cs
Created September 21, 2012 04:21
TimeUUID Generator for .NET
using System;
namespace FluentCassandra
{
/// <summary>
/// Used for generating UUID based on RFC 4122.
/// </summary>
/// <seealso href="http://www.ietf.org/rfc/rfc4122.txt">RFC 4122 - A Universally Unique IDentifier (UUID) URN Namespace</seealso>
public static partial class GuidGenerator
{
@nberardi
nberardi / IObjectContext.cs
Created November 17, 2010 23:25
Code for my post on Repository Pattern for Entity Framework: http://coderjournal.com/2010/11/entity-framework-repository-pattern/
public interface IObjectContext : IDisposable
{
ObjectContextOptions ContextOptions { get; }
TEntity CreateObject<TEntity>() where TEntity : class;
IObjectSet<TEntity> CreateObjectSet<TEntity>() where TEntity : class;
int SaveChanges();
}
@nberardi
nberardi / on-model-3-charging.json
Created March 6, 2023 15:08
Node Red - On Model 3 Charging Adjust Amperage From Car To Maximize Sun Without Grid Usage
[
{
"id": "d20b09cd596147aa",
"type": "tab",
"label": "On Model 3 charging",
"disabled": false,
"info": "",
"env": []
},
{
server version: 0.6.26
plugin version: @scrypted/webrtc 0.1.36
plugin loaded
[Test] remote options {
proxy: false,
offer: {
type: 'offer',
sdp: 'v=0\r\n' +
'o=- 3887398039 3887398039 IN IP4 0.0.0.0\r\n' +
's=a 2 z\r\n' +
@nberardi
nberardi / Poker.cs
Last active September 25, 2020 13:12
Consensus: SignalR + TypeScript found here http://coderjournal.com/2013/07/signalr-and-typescript/
namespace Consensus.Hubs
{
public class Poker : Hub
{
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
private static Dictionary<string, PokerUser> _users = new Dictionary<string, PokerUser>();
private static List<PokerRoom> _rooms = new List<PokerRoom>();
public PokerUser Join(PokerUser user)
@nberardi
nberardi / FacebookGroupDelete.js
Created February 13, 2020 08:49
Allows you to delete all the members from a Facebook group, so that it can be removed.
var _memberMenus = document.getElementsByTagName('button');
var _confirmed = false;
var _i = 0;
var _f = 0;
var _resetAttempted = false;
var _waitCount = 0;
function clickMemberMenu() {
if (typeof(_memberMenus[_f]) !== 'undefined' && _memberMenus[_f].getAttribute('aria-label') == 'Member Settings') {
_resetAttempted = false;
@nberardi
nberardi / SequentialNumberGenerator.cs
Created January 19, 2012 17:39
Sequential Number Generator for RavenDB
private static readonly object GeneratorLock = new object();
///<summary>
/// Create the next id (numeric)
///</summary>
private int NextAccountNumber()
{
lock (GeneratorLock)
{
using (new TransactionScope(TransactionScopeOption.Suppress))
public class MefControllerFactory : IControllerFactory
{
private readonly WebScopedContainerManager _containerManager;
public MefControllerFactory(WebScopedContainerManager containerManager)
{
_containerManager = containerManager;
}
#region IControllerFactory Members
@nberardi
nberardi / NSUrlSessionHandler.cs
Last active May 4, 2016 21:23
A rethinking of the NSUrlSessionHandler.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;