Skip to content

Instantly share code, notes, and snippets.

View justjkk's full-sized avatar

J Kishore Kumar justjkk

  • Bangalore, India
View GitHub Profile
@justjkk
justjkk / myDes.c
Created July 14, 2010 16:08
DES Implementation ***EXPERIMENTAL**
/*
* Assumptions/Limitations:
* 1. gcc compiler is used.
* 2. byte is 8 bits long.(sizeof(char)==1)
* 3. word is 32 bits long.(sizeof(int)==4)
* 4. dword is 64 bits long.
*/
#include "assert.h"
#include "stdio.h"
#include "string.h"
@justjkk
justjkk / rounded.css
Created July 9, 2010 16:16
'Lost & Found' for css
pre {
margin-left: 2em;
background-color: #f8f8ff;
font-size: 11px;
padding: 3px 5px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
-o-border-radius: 4px;
-ms-border-radius: 4px;
-khtml-border-radius: 4px;
import java.io.*;
class Rational
{
/*
* Object oriented concept is misused here. Rational class doesn't need a
* isPrime() method. isPrime() should ideally come under the Integer class
*/
boolean isPrime(int n) // Java has boolean datatype
{
if(n < 2) // Remember, Prime numbers starts from 2
@justjkk
justjkk / linkedlist.c
Created June 13, 2010 18:26
LinkedListProblems
#include<stdio.h>
#include<stdlib.h>
typedef struct node {
int val;
struct node *next;
}List;
int Length(List *head)
{
int len=0;
@justjkk
justjkk / LICENSE
Last active January 7, 2025 17:30
Parsing JSON with lex and yacc
The MIT License (MIT)
Copyright (c) 2015 J Kishore Kumar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
%{
#include<stdio.h>
//#include<string.h>
//#define YYSTYPE char *
#define yyerror(X) printf(X)
%}
%%
START: A 'c' B {printf("AND");}
;
A: 'a' {printf("alpha");}
@justjkk
justjkk / tsvToJson.l
Created June 11, 2010 17:49
Convert Data from TSV to JSON for use in Django Models
%{
#include<stdio.h>
#include<string.h>
#define MAX_COLUMN_COUNT 256
#define STARTING_PK 1
#define MODEL_NAME "sample.model"
typedef enum {false,true} bool;
int noc=0,pk=STARTING_PK-1,ci=0;
bool is_header=true,is_first_record=true,read_column_name=true,read_column_value=false,write_new_record=false;
@justjkk
justjkk / Stringfns.c
Created June 10, 2010 11:24 — forked from Nachiappan/Stringfns.c
String Functions in C
#include<stdio.h>
#include<stdlib.h>
#define ARRAY_SIZE 15
typedef enum {false, true} bool;
int leng(char *ipstr)
{
int i = 0;
while(ipstr[i] != '\0')
i++;
return i;
@justjkk
justjkk / revision_stages.py
Created May 31, 2010 06:31
Scribbles of Python scripts that are used in wtfimb shell
''' Python Script to show changes to Stages '''
STAGE = 12 # content_type id differs from one database copy to another
from stages.models import Stage
from reversion.models import Version
[[Stage.objects.get(pk=s.object_id).display_name,s.revision.date_created.__str__()] for s in Version.objects.filter(revision__user__isnull = False).filter(content_type=STAGE)]
@justjkk
justjkk / ack_short.py
Created May 20, 2010 18:43
Ackermann Function in python
import sys
count=0
sys.setrecursionlimit(50000)
cache={}
def a(m,n):
global count
global cache
count=count+1
if cache.has_key(m) and cache[m].has_key(n):
return cache[m][n]