Skip to content

Instantly share code, notes, and snippets.

@dmjio
dmjio / gist:1371311
Created November 16, 2011 20:42
convert json date to javascript date
convertDate: function (jsonDate) {
var someDate = new Date(+jsonDate.replace(/\/Date\((-?\d+)\)\//gi, "$1"));
return someDate;
@dmjio
dmjio / how to sort an array of objects in javascript
Created January 3, 2012 17:21
how to sort an array of objects in javascript
data.sort( function(a, b) {return b.count - a.count} );
@dmjio
dmjio / BinarySearch
Created February 27, 2012 06:06
BinarySearch
static int BinarySearch(int[] arr, int x)
{
int i = 0;
int m = 0;
int j = arr.Length - 1;
while (i < j)
{
m = ((i+j)/2);
if (x > arr[m])
i = m + 1;
@dmjio
dmjio / LinearSearch
Created February 27, 2012 06:06
LinearSearch
public int LinearSearch(int[] arr, int x)
{
int i = 0;
int location = 0;
int n = arr.Length -1;
while (i < n && arr[i] != x)
{
i++;
}
if (i < n)
@dmjio
dmjio / Inversion Finder
Created April 2, 2012 03:50
Recursive && Non-Recursive Inversion Finder
public class Program
{
static void Main(string[] args)
{
var list = new int[] { 1, 5, 4, 8, 10, 2, 6, 9, 12, 11, 3, 7 };
var a = InversionCounter(list, 0, 1, 0);
Console.WriteLine(a);
Console.ReadLine();
}
@dmjio
dmjio / Merger
Created May 22, 2012 18:19
Merge Two Dictionaries
void Main()
{
var d1 = new Dictionary<string, int>
{
{ "a" , 1 },
{ "b" , 2 }
};
var d2 = new Dictionary<string, int>
{
@dmjio
dmjio / fib in python
Created May 30, 2012 18:50
fibonacci in python
def fib(n):
#display fib numbers from 0 to n
a, b = 0, 1
while b < n:
print b,
a, b = b, a + b
@dmjio
dmjio / rollback
Created May 31, 2012 05:20
Sql Trans roll back
SET XACT_ABORT ON
BEGIN TRY
BEGIN TRAN
--select * from vendor where vendorid = '37febdc9-a471-458c-b6b9-058ff69a85d3'
--select * from document
PRINT 'All statements executed, manually commit'
-- COMMIT
def GetMilk():
if eggs:
return BuyMilk(6)
else:
return BuyMilk(1)
@dmjio
dmjio / Stats.hs
Last active November 7, 2020 21:14
Mean, Standard Deviation, Variance in Haskell
module Main where
import Control.Applicative
{- Result = (Mean = 0.34, St. Dev = 0.115, Variance = 0.005) -}
main :: IO ()
main = interact stats
where
length' = fromIntegral . length
stats d = show (avg, stdDev, variance)