Skip to content

Instantly share code, notes, and snippets.

View kedarmhaswade's full-sized avatar
💭
Just trying to catch up with my calendar

Kedar Mhaswade kedarmhaswade

💭
Just trying to catch up with my calendar
View GitHub Profile
@kedarmhaswade
kedarmhaswade / .ruby-gemset
Last active February 22, 2021 13:49
Learning SQL (O'Reilly) With SQLite instead of MySQL
global
@kedarmhaswade
kedarmhaswade / learningsql.mysql
Last active August 29, 2015 14:18
learning.sql from http://examples.oreilly.com/9780596007270/ translated to sqlite3 instead of MySQL -- this can be easily imported into sqlite3: sqlite3 learningsql.sqlite3
/* begin table creation */
drop database if exists learningsql;
create database learningsql;
use learningsql;
create table department
(dept_id smallint unsigned not null auto_increment,
name varchar(20) not null,
constraint pk_department primary key (dept_id)
);
@kedarmhaswade
kedarmhaswade / Tree.java
Created March 26, 2015 00:41
Inorder tree walk ...
class Tree {
Tree left, right;
int key;
static void inorder(Tree r) {
if (r != null) {
inorder(r.left);
System.out.println(r.key);
inorder(r.right);
}
}
@kedarmhaswade
kedarmhaswade / TreePrintGoto.java
Created March 25, 2015 12:30
Java does not have goto
/**
* This is from Donald Knuth's famous paper: Structured Programming with Goto.
* You are printing a binary tree using the Goto statement. The traversal is inorder.
*/
class TreePrintGoto {
private final static class Node {
Node left, right;
final int key;
Node(int key) {
this.key = key;
@kedarmhaswade
kedarmhaswade / cygwin-mirror.md
Last active August 29, 2015 14:17
The way to set up a new mirror for your cygwin ...

The Internets are full of information about how to set up your own cygwin morror. But this gist tells you how to set up a mirror that is nearby your computer.

The command is: apt-cyg update --mirror (mirror-url), e.g. for CA, USA:

apt-cyg update --mirror http://mirrors.kernel.org/sourceware/cygwin/

The list of mirrors is here. Enjoy!

#include<stdio.h>
#include<errno.h>
#include<stdlib.h>
#include<string.h>
int main(int argc, char**argv) {
if (argc < 2) {
printf("Usage: %s <errno>\n", argv[0]);
exit(1);
}
int err = atoi(argv[1]);
@kedarmhaswade
kedarmhaswade / MedianSortedArrays.java
Last active August 29, 2015 14:13
Finding the median of two sorted algorithm a log^2 algorithm
/**
* You are given two sorted arrays. The goal is to find their median.
* Median of a *sorted* array of length n is the element at index n-1/2 (when n is even, we consider only the lower median).
* We can solve this problem is two ways:
* 1) A merging algorithm that merges the two arrays of length m and n and gets the (m+n-1)/2 th element. This needs
* an O(n) space (without the in-place merging techniques).
* 2) A merging algorithm using binary search.
** Perhaps some optimization is possible.
*/
class MedianSortedArrays {
/** Studies Java Memory */
import java.util.*;
import java.io.*;
public class JavaMemory {
static volatile boolean stop = false;
public static void main(String[] args) throws Exception {
System.out.println("Hope you ran it with -Xmx32m");
Thread alloc = new Thread(new Allocator());
alloc.start();
}
import java.util.*;
import java.io.*;
public class Threads {
static volatile boolean stop = false;
static volatile boolean stopMain = false;
public static void main(String[] args) throws Exception {
Thread reader = new Thread(new Reader());
reader.start();
while (!Threads.stopMain) {
;