Skip to content

Instantly share code, notes, and snippets.

@dmjio
dmjio / gist:1371311
Created Nov 16, 2011
convert json date to javascript date
View gist:1371311
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 Jan 3, 2012
how to sort an array of objects in javascript
View how to sort an array of objects in javascript
data.sort( function(a, b) {return b.count - a.count} );
View 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;
View 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 Apr 2, 2012
Recursive && Non-Recursive Inversion Finder
View 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
Merge Two Dictionaries
View Merger
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
fibonacci in python
View fib 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
Sql Trans roll back
View rollback
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
View gist:2871725
def GetMilk():
if eggs:
return BuyMilk(6)
else:
return BuyMilk(1)
@dmjio
dmjio / Stats.hs
Last active Nov 7, 2020
Mean, Standard Deviation, Variance in Haskell
View Stats.hs
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)