Skip to content

Instantly share code, notes, and snippets.

View k4rtik's full-sized avatar

Kartik Singhal k4rtik

View GitHub Profile
@k4rtik
k4rtik / kvm-check.sh
Created October 23, 2012 12:59
Simple utility to check whether KVM is installed, loaded and running, wrote for Fedora 17 platform for IBM Virtual Tux contest.
#!/bin/bash
echo Checking if required packages are installed...
rpm -q qemu-kvm python-virtinst libvirt | grep not
echo Done.
echo
echo Loaded kvm kernel modules:
lsmod | grep kvm_intel
@k4rtik
k4rtik / lift-scheduler.py
Created October 2, 2012 06:02
A simple lift scheduler program using nearest car approach
#!/usr/bin/python
# Assume there is a 50 storey building and it has 4 lifts. You have to write a
# scheduler program for the lifts. All the 4 lifts will be controlled by
# single program and Waiting time for peoples waiting for lift should be
# minimum.
#
# Using the Nearest Car approach described at http://www.quora.com/Is-there-any-public-elevator-scheduling-algorithm-standard
#
# Some assumptions include direction of lift at top floor will always be down,
# and on ground floor it will be up. More assumptions obvious from the code.
@k4rtik
k4rtik / subquadratic-maxsum.c
Created October 1, 2012 13:51
O(n lg n) program to find the max sum in a subsequence in an array of numbers.
// Program to find the max sum in a subsequence in an array of numbers.
//
// Adapted from the O(n lg n) algorithm described by Jon Bentley in his famouos
// collection of programming columns - Programming Pearls.
//
// Author: Kartik Singhal
// Date: October 1, 2012
#include <stdio.h>
@k4rtik
k4rtik / scanning-maxsum.c
Created October 1, 2012 13:38
Linear time program to find the max sum in a subsequence in an array of numbers.
// Program to find the max sum in a subsequence in an array of numbers.
//
// Adapted from the linear time scanning algorithm described by Jon Bentley in
// his famouos collection of programming columns - Programming Pearls.
//
// Author: Kartik Singhal
// Date: October 1, 2012
#include <stdio.h>
@k4rtik
k4rtik / .vimrc
Last active October 4, 2015 15:58
My custom vimrc
" URL: http://vim.wikia.com/wiki/Example_vimrc
" Authors: http://vim.wikia.com/wiki/Vim_on_Freenode
" Description: A minimal, but feature rich, example .vimrc. If you are a
" newbie, basing your first .vimrc on this file is a good choice.
" If you're a more advanced user, building your own .vimrc based
" on this file is still a good idea.
"------------------------------------------------------------
" Features {{{1
"
@k4rtik
k4rtik / temp.sh
Created April 28, 2012 13:10
Simple script to let me know the temperatures of my laptop, hddtemp requires sudo making this script more than 3 lines.
#!/bin/bash
sensors
aticonfig --odgt
answer="N"
if [ "$(whoami)" != "root" ]; then
echo -ne "\n\nDo you want to know hard disk temperature (requires sudo)? (y/N) "
read answer
if [ "$answer" == "y" ]; then
@k4rtik
k4rtik / distance.cpp
Created December 10, 2011 02:44
Some object oriented code that was asked in the practical in first year - November 10, 2009
#include <iostream>
using namespace std;
class DB;
class DM
{
int metres;
int cms;
public:
@k4rtik
k4rtik / string-func.cpp
Created December 10, 2011 02:42
generates email IDs and stores them in a file - first year programming assignment - September 23, 2009
// file: string-func.cpp
// generates email IDs and stores them in a file
// author: Kartik Singhal
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;
int main()
@k4rtik
k4rtik / sicp-download.sh
Created December 10, 2011 00:32
The bash script I created for simultaneously downloading videos of MIT's SICP course. - October 2010
#!/bin/bash
baseurl="http://www.archive.org/download/MIT_Structure_of_Computer_Programs_1986/lec"
urlend="b_512kb.mp4"
log="log_b"
for i in {5..7}
do
nohup wget -c "${baseurl}$i${urlend}" > "${log}$i" &
done
@k4rtik
k4rtik / ieee754.c
Created December 9, 2011 23:23
Program to check whether the compiler converts a given floating point number to the IEEE 754 specification. - February 25, 2011
/*
* ieee754.c
*
* Program to check whether the compiler converts a given floating point number
* to the IEEE 754 specification.
*
* Original Authors: Mohammed Hashir and Ashwin Jacob
* This is a slightly modified and improved version by
*
* Kartik Singhal - B090566CS