Skip to content

Instantly share code, notes, and snippets.

View rishi93's full-sized avatar

Rajarishi Devarajan rishi93

View GitHub Profile
@rishi93
rishi93 / sync.java
Last active November 27, 2015 12:48
Synchronized function in Multithreading
/*Synchronized means the code is available to only thread at a time */
import java.io.*;
class Routine
{
private String msg;
Routine(String msg)
{
this.msg = msg;
}
@rishi93
rishi93 / sync2.java
Last active November 27, 2015 12:52
Synchronized block in Multithreading
/*synchronized means only thread has access to it at a time */
import java.io.*;
class Routine
{
private String msg;
Routine(String msg)
{
this.msg = msg;
}
@rishi93
rishi93 / Main.java
Last active December 1, 2015 09:16
Producer Consumer Problem
import java.io.*;
import java.lang.*;
class Factory
{
private int contents;
private boolean available = false;
public synchronized int get()
{
@rishi93
rishi93 / posting.py
Created February 22, 2016 09:26
POSTing and GETing in Python
#from urllib import urlopen
#url = "https://api.thingspeak.com/update?api_key=SR5SPU47GKH6MXT9&field1=17235"
#response = urlopen(url).read()
#print response
import urllib2
import urllib
query_args = { 'name':'Active','phone':'Active','address':'from python' }
@rishi93
rishi93 / basket.py
Last active February 23, 2016 14:52
rfid shopping basket
from urllib import urlopen
url = "http://data.sparkfun.com/input/7JAm8EYLolf0yYZ2xolq?private_key=mzVy8NMJp4TyX1j0mVRK&rfid_code=" #GET request
def checkIfAlreadyPresent(arr,item):
for i in arr:
if item == i:
return True
return False
@rishi93
rishi93 / test1.cpp
Last active August 15, 2016 18:29
Prime Generator - PRIME1
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
//For Fast IO
ios_base::sync_with_stdio(false);
@rishi93
rishi93 / test1.cpp
Last active August 20, 2016 13:04
Factorial Trailing Zeros - FCTRL
#include <iostream>
using namespace std;
int noOfTrailingZeros(int n){
int count = 0;
int divisor = 5;
//First, we count the number of multiples of 5 in the expansion of n!
//Then we count the number of multiples of 25, and then 125, and so on..
while(divisor <= n){
@rishi93
rishi93 / test1.cpp
Last active August 16, 2016 11:25
Transform the Expression - ONP
#include <iostream>
#include <stack>
using namespace std;
string reversePolishNotation(string expression){
stack<char> operatorStack;
string result = "";
for(int i=0; i<expression.length(); i++){
//If it is '(' then ignore
@rishi93
rishi93 / test1.cpp
Last active August 16, 2016 10:51
Next Palindrome - PALIN
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string createLeftMirrored(string num){
int len = num.length();
//If number is of even length
if(len % 2 == 0){
@rishi93
rishi93 / test1.py
Last active March 24, 2016 06:12
Prime or not using Fermat's Theorem - PON
from random import randint
def gcd(a,b):
while a > 0 and b > 0:
if a > b:
a = a % b
else:
b = b % a
if a == 0:
return b