Skip to content

Instantly share code, notes, and snippets.

View shkesar's full-sized avatar

Shubham Keserwani shkesar

View GitHub Profile
trait Component {
val childrens = new collection.mutable.ArrayBuffer[Component]()
//val parent: Component
def operation: Unit
def add(component: Component) = ()
def remove(component: Component) = ()
def getChildrens: Iterator[Component] = collection.Iterator.empty
}
@shkesar
shkesar / malloc.c
Created February 7, 2016 14:57
Memory allocator
#include <assert.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
void *malloc(size_t size) {
void *p = sbrk(0);
void *request = sbrk(size);
if (request == (void*) -1) {
@shkesar
shkesar / gantt-chart.html
Last active March 30, 2016 08:48
Gantt Chart
<html>
<head>
<title>Gantt chart</title>
<style type="text/css">
.process {
}
#input {
}
#add-process-button {
def nQueens(n: Int) = (0 until n).permutations filter {p =>
val i = p.zipWithIndex.toSet // p[i] is the column of the queen on ith row (must be a permutation of 0 until n)
i.map{case (c, d) => c + d}.size == n && // No 2 queens can have same col + diag
i.map{case (c, d) => c - d}.size == n // No 2 queens can have same col - diag
}
for {
(solution, num) <- nQueens(8).zipWithIndex
_ = println(s"Solution #${num + 1}:")
col <- solution
@shkesar
shkesar / MPlayer.java
Created May 2, 2016 06:16
Music Player using JavaFX
package com.github.shkesar.JMusic;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
@shkesar
shkesar / config.py
Created May 2, 2016 06:19
NLP in python to test sentiments in mailbox
import nltk
nltk.download('stopwords')
@shkesar
shkesar / index.html
Created May 2, 2016 06:21
A very simple notes taking app using HTML5 local storage
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Notes</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
@shkesar
shkesar / cipher.c
Last active August 13, 2016 10:44
XOR based cipher program in C
#include <stdio.h>
#include <stdlib.h>
#define MAX_LEN 1024
int main(int argc, char const *argv[])
{
char *plain = malloc(MAX_LEN * sizeof(int));
char *pass = malloc(MAX_LEN * sizeof(int));
@shkesar
shkesar / data_validation.c
Created August 18, 2016 08:55
Internshala programming problem
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
int data_validation(char *fmt, char *data) {
while (*data) {
if (*fmt == 'a' && !isalpha(*data)) return 0;
else if (*fmt == 'n' && !isdigit(*data)) return 0;
else if (*fmt == 'x' && !isalnum(*data)) return 0;
else if (*fmt == '*') return 1;
@shkesar
shkesar / second_smallest_marks_students.py
Created September 7, 2016 16:20
Hacker rank problem
no = int(input())
students = []
for i in range(no):
name = str(raw_input("Enter name: "))
marks = float(raw_input("Enter marks: "))
students.append([name, marks])
smallest = min(students, key=lambda x: x[1])