Skip to content

Instantly share code, notes, and snippets.

Avatar

Horacio Nunez hnh12358

View GitHub Profile
View contexts
using System;
namespace CSharpAdventures
{
class MainClass
{
public static void Main (string[] args)
{
int max = Int32.MaxValue;
View arithmetic
using System;
namespace CSharpAdventures
{
class MainClass
{
public static void Main (string[] args)
{
int max = Int32.MaxValue;
Console.WriteLine (CheckedSum(UncheckedSum(max,1),1)); //Doesn't Break.
//Console.WriteLine (UncheckedSum(CheckedSum(max,1),1)); //Will Break!
View intheend
// In the end
if (newIndex == this.stepsInfo.Count)
{
return false; // It doesn't even matter
}
View ResharperNoDetectingAllEnumValuesAreBeingUse
public void Foo(MailBodyFormat bodyFormat) {
string emailBody;
switch (bodyFormat)
{
case MailBodyFormat.PlainText:
isHtml = false;
emailBody = body;
break;
View ObjectHelper.cs
//After working with a Functional Language I can't help to think that the world will be more
//safe without all the need to be checking for null values.
//This is an small helper I wrote to stop writing 'null' every once in a while.
namespace Horacio.Helpers
{
using System.Net.NetworkInformation;
public static class ObjectHelper
{
@hnh12358
hnh12358 / functional-matrixs.fs
Created Apr 8, 2011
Building Simple Functional Mtrixs
View functional-matrixs.fs
let empty m n =
requires (m = 0 || n = 0) MATRIX_EMPTYCREATION_BADDIMENSIONS
new FMatrix(m,n, fun (i,j) -> failwith MATRIX_EMPTY )
let identity m =
requires (m >= 0) MATRIX_IDENTITYCREATION_BADDIMENSIONS
if m = 0 then
empty 0 0
else
new FMatrix(m,m, fun (i,j) -> if i = j then 1.0 else 0.0)
@hnh12358
hnh12358 / verifying-ramanujan-1-over-pi.py
Created Mar 14, 2011
Verify the Ramanujan's 1/pi formula for 1000 digits of pi.
View verifying-ramanujan-1-over-pi.py
##author: Horacio Nunez
import decimal, math, functools
D = decimal.Decimal
C = decimal.getcontext()
C.prec = 1024
def multiply(x,y): return C.multiply(x,y)
View gist:598786
function [Result ResultSudoku] = ResolveSudoku(InputSudoku)
A = [1 2 3 4 5 6 7 8 9];
B = [1 2 3 4 4 5 5 6 6 7 7 7 8 8 8 9 9 9];
C = [1 2 2 3 3 3 4 5 5 6 6 6 7 8 8 9 9 9];
f = @(x) sum(sum(power(2,x))) / 1022;
g = @(m,r,c) [m(3*r-2,3*c-2:3*c) m(3*r-1,3*c-2:3*c) m(3*r,3*c-2:3*c)];
j = @(m,r,c) g(m,sum(B == r),sum(B == c));
h = @(m,r,c) intersect(intersect(setdiff(A,m(r,:)),setdiff(A,m(:,c))),setdiff(A,j(m,r,c)));
function [R RS] = Resolve(IS,ESC)
if ESC == 0
View gist:598695
let empty m n =
requires (m = 0 || n = 0) MATRIX_EMPTYCREATION_BADDIMENSIONS
new FMatrix(m,n, fun (i,j) -> failwith MATRIX_EMPTY )
let identity m =
requires (m >= 0) MATRIX_IDENTITYCREATION_BADDIMENSIONS
if m = 0 then
empty 0 0
else
new FMatrix(m,m, fun (i,j) -> if i = j then 1.0 else 0.0)