This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.lang.*; | |
class Factory | |
{ | |
private int contents; | |
private boolean available = false; | |
public synchronized int get() | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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' } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
int main(){ | |
//For Fast IO | |
ios_base::sync_with_stdio(false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |