Skip to content

Instantly share code, notes, and snippets.

View jayeshcp's full-sized avatar
🏎️

Jayesh Chandrapal jayeshcp

🏎️
View GitHub Profile
@jayeshcp
jayeshcp / FileRead.java
Created January 7, 2015 15:37
Reading integers from data file
import java.io.File;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
public class FileRead {
public static void main(String[] args) {
BufferedReader bf = null;
try {
@jayeshcp
jayeshcp / RegexDemo.java
Created January 7, 2015 15:39
Search for occurrence of string using Pattern and Matcher
import java.util.regex.*;
public class RegexDemo {
public static final String SAMPLE_STRING = "Perfection is not attainable, but if we chase perfection we can catch excellence";
public static void main(String[] args) {
//pattern to compare \\b matches word boundaries, so
//the below pattern only matches we
String searchStr = "we";
Pattern pattern = Pattern.compile("\\b" + searchStr + "\\b");
@jayeshcp
jayeshcp / FindDuplicates.java
Last active August 29, 2015 14:13
Find duplicate elements in array in O(N) time
/* Find if given array has duplicate elements (more than 1 occurence)
Time Constraint: O(N)
Author: Jayesh CP
*/
import java.util.*;
import java.lang.*;
import java.io.*;
public class FindDuplicates
@jayeshcp
jayeshcp / Unit Testing in Python.md
Last active April 4, 2016 15:37
Unit Testing in Python
  • A testcase is created by subclassing unittest.TestCase.
  • Individual tests are defined with methods whose names start with the letters "test". This naming convention informs the test runner about which methods represent tests.
  • Following is a typical example of unit test:
# PythonUnitTest.py

import unittest

class Sort(unittest.TestCase):
    def setUp(self):
@jayeshcp
jayeshcp / ConvertSec2DaysHoursMinsSecs.java
Last active September 22, 2015 12:00
Convert seconds to Days, Hours, Mins, Secs
public static void ConvertSec2DaysHoursMinsSecs(int timeDiff) {
int days = (int) Math.floor(timeDiff / 86400);
int hour = (int) Math.floor((timeDiff % 86400) / 3600);
int min = (int) Math.floor((timeDiff % 3600) / 60);
int sec = (int) (timeDiff % 60);
System.out.println("(" + days + " " + hour + " " + min + " " + sec + ")");
}

Tech Interview Cheat Sheet

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. Originally forked from Tristan Siegel's Gist.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
@jayeshcp
jayeshcp / barchartinR.md
Last active August 29, 2015 14:22
Plotting simple bar chart in T

Script:

# Read table data from csv file
data <- read.table("data.csv", header=T, sep=",")

# Start PDF device driver to save output to skills.pdf
pdf(file="skills.pdf", height=3.5, width=5)

# Draw bar chart
@jayeshcp
jayeshcp / QueryBoard.java
Last active September 22, 2015 11:53
Basic jUnit Test Case
/**
* Sample class file for above unit tests
*/
public class QueryBoard {
int[] nums;
QueryBoard() {
nums = new int[10];
}
@jayeshcp
jayeshcp / index.html
Created April 16, 2016 21:48
Responsive Grids
<div class="col-12">
<h1>Header</h1>
</div>
<div class="col-3">
<ul>
<li>Menu 1</li>
<li>Menu 2</li>
<li>Menu 3</li>
<li>Menu 4</li>