Skip to content

Instantly share code, notes, and snippets.

Avatar
🤠
I may be slow to respond.

Arun Karunagath kra3

🤠
I may be slow to respond.
View GitHub Profile
@kra3
kra3 / tictactoe.py
Created May 11, 2011
Retro "Tic Tac Toe" in python, wrote for fun
View tictactoe.py
#! /usr/bin/env python
# All right reserved. Distributed Under BSD Lisence
__author__="Arun.K.R <the1.arun@gmail.com>"
__date__ ="$May 11, 2011 6:23:17 PM$"
import os, time
from random import choice
WIDTH = 3
@kra3
kra3 / first_sorted.py
Created Sep 19, 2011
First implementation
View first_sorted.py
def compare(x, y):
return y < x
def cmp_to_key(mycmp, col, covert_to_proper_datatype):
class K(object):
class K(object):
def __init__(self, obj, *args):
self.obj = obj
def __lt__(self, other):
return mycmp(covert_to_proper_datatype(self.obj[col]), covert_to_proper_datatype(other.obj[col])) == False
@kra3
kra3 / second_sort.py
Created Sep 19, 2011
Seconed refinement
View second_sort.py
def cmp_to_key(col, covert_to_proper_datatype, cmpr = (lambda x, y: x < y)):
class K(object):
def __init__(self, obj, *args):
self.obj = obj
def __lt__(self, other):
return cpmr(covert_to_proper_datatype(self.obj[col]), covert_to_proper_datatype(other.obj[col])) == True
return K
@kra3
kra3 / third_sort.py
Created Sep 19, 2011
3rd refinement
View third_sort.py
def cmp_to_key(col, covert_to_proper_datatype):
#Discrad this approch, once we have an option to sort via webmethods, sorting by DB engine is more efficient than doing it ourselves.
class K(object):
def __init__(self, obj, *args):
self.obj = obj
def __lt__(self, other):
return covert_to_proper_datatype(self.obj[col]) < covert_to_proper_datatype(other.obj[col])
return K
@kra3
kra3 / dict_map_sort.py
Created Sep 19, 2011
mapped dict for sorting
View dict_map_sort.py
mapping_tbl = []
mapping_tbl.insert(0, lambda x: int(m.parseString(x).childNodes[0].childNodes[0].nodeValue))
mapping_tbl.insert(1, lambda x: x.lower())
mapping_tbl.insert(2, lambda x: x.lower())
mapping_tbl.insert(3, lambda x: int(x))
mapping_tbl.insert(4, lambda x: datetime.strptime(x, "%m/%d/%Y"))
mapping_tbl.insert(5, lambda x: int(x.replace('-', '')))
mapping_tbl.insert(6, lambda x: datetime.strptime(x, "%m/%d/%Y"))
mapping_tbl.insert(7, lambda x: datetime.strptime(x, "%m/%d/%Y"))
mapping_tbl.insert(8, lambda x: x.lower())
@kra3
kra3 / refined_map_sort.py
Created Sep 19, 2011
Mapping is again refined
View refined_map_sort.py
mapping_functions = {
'str_lower' : lambda x: x.lower(),
'date_mdY' : lambda x: datetime.strptime(x, "%m/%d/%Y"),
'ssn' : lambda x: int(x.replace('-', ''))
'int' : lambda x: int(x)
'dom' : lambda x: int(m.parseString(x).childNodes[0].childNodes[0].nodeValue)
}
mapping_tbl = []
mapping_tbl.insert(0, mapping_functions['dom'])
View in_effective_sort.py
sorted([[5, 'Man', 1], [2, 'Arun', 6], [4, 'Dummy', 6], [1, 'Naveen', 3], [3, 'Bajsd', 7]], key=lambda x: str(x[1]).lower())
View in_effective_sort.py
sorted([[5, 'Man', 1], [2, 'Arun', 6], [4, 'Dummy', 6], [1, 'Naveen', 3], [3, 'Bajsd', 7]], key=lambda x: str(x[1]).lower())
@kra3
kra3 / final_Sort.py
Created Sep 19, 2011
final solution
View final_Sort.py
from datetime import datetime
import xml.dom.minidom as m
def cmp_to_key(col, covert_to_proper_datatype):
class K(object):
def __init__(self, obj, *args):
self.obj = obj
def __lt__(self, other):
return covert_to_proper_datatype(self.obj[col]) < covert_to_proper_datatype(other.obj[col])
return K
View first.c
struct User{
char name[45];
int age;
float height;
}usr;
usr.name = "Someone";
usr.age = 31;
ur.height = 6.1;