Skip to content

Instantly share code, notes, and snippets.

View sdmcraft's full-sized avatar

Satya Deep Maheshwari sdmcraft

View GitHub Profile
import java.util.ArrayList;
import java.util.List;
class Solution {
public boolean canFinish(int numTasks, int[][] prerequisites) {
List<Integer>[] adjacencyList = new ArrayList[numTasks];
int[] prereqCount = new int[numTasks];
for (int i = 0; i < prerequisites.length; i++) {
if(adjacencyList[prerequisites[i][1]] == null) {
adjacencyList[prerequisites[i][1]] = new ArrayList<>();
}
import java.util.ArrayList;
import java.util.List;
class Solution {
public boolean canFinish(int numTasks, int[][] prerequisites) {
...
for (int i = 0; i < numTasks; i++) {
if (adjacencyList[i] != null) {
return false;
}
}
import java.util.ArrayList;
import java.util.List;
class Solution {
public boolean canFinish(int numTasks, int[][] prerequisites) {
...
boolean proceed = true;
while (proceed) {
proceed = false;
for (int i = 0; i < numTasks; i++) {
if (prereqCount[i] == 0 && adjacencyList[i] != null) {
import java.util.ArrayList;
import java.util.List;
class Solution {
public boolean canFinish(int numTasks, int[][] prerequisites) {
List<Integer>[] adjacencyList = new ArrayList[numTasks];
int[] prereqCount = new int[numTasks];
for (int i = 0; i < prerequisites.length; i++) {
if(adjacencyList[prerequisites[i][1]] == null) {
adjacencyList[prerequisites[i][1]] = new ArrayList<>();
}
@sdmcraft
sdmcraft / graphstream.css
Last active June 11, 2020 06:00
GraphStream Stylesheet
node {
size: 30px;
fill-color: #777;
z-index: 0;
}
edge {
shape: line;
fill-color: #222;
arrow-size: 8px, 5px;
@sdmcraft
sdmcraft / append-garbage.sh
Created February 12, 2019 11:31
Append garbage to files
#!/bin/bash
usage()
{
echo -e "Usage: $0 -i <input folder path containing files to append garbage> -b <garbage size>" \
"\nExample Usage: ./append-garbage.sh -i ~/Pictures/000-large -b 10M" 1>&2; exit 1;
}
while getopts i:b: option
do
case "${option}"
in
@sdmcraft
sdmcraft / count-pattern.sh
Last active February 2, 2018 06:01
Find the counts of a pattern across files in a folder
#!/bin/sh
usage()
{
echo -e "Usage: $0 -i <input folder path containing files to search> -j <file name pattern> -p <pattern to search> -e <pattern to exclude from search results> -l <Character to compare for uniqueness> -f <Number of prefix fields to ignore while printing matching lines" \
"\nExample Usage: ./count-pattern.sh -i /mnt/installation/crx-quickstart/logs -j *log* -p *ERROR* -e 'Non-existant pattern' -l 25 -f 6" 1>&2; exit 1;
}
while getopts i:j:p:e:l:f: option
do
case "${option}"
in
@sdmcraft
sdmcraft / upload-files.sh
Created November 30, 2017 10:59
Script to upload all files in a folder to a server
#!/bin/sh
usage()
{
echo -e "Usage: $0 -i <input folder path containing files to upload> -c <credentials of the server to upload to> -u <url to upload to>" \
"\nExample Usage: ./upload-files.sh -i /src/folder -u http://server.com/path -c user:password" 1>&2; exit 1;
}
while getopts i:u:c: option
do
case "${option}"
in
@sdmcraft
sdmcraft / create-noise.sh
Created November 30, 2017 10:25
Create noisy copies of images
#!/bin/sh
usage()
{
echo -e "Usage: $0 -c <number of noisy copies per image> -s <source folder containing images> -p <image name pattern> -d <destination folder to keep noisy images>" \
"\nExample Usage: ./create-noise.sh -c 10 -s /home/satyadeep/Pictures/000 -p '*.jpg' -d /home/satyadeep/temp/tst" 1>&2; exit 1;
}
while getopts c:s:p:d: option
do
case "${option}"
in
@sdmcraft
sdmcraft / setup-java.sh
Last active November 12, 2020 11:03
Setup java on linux
cd /opt/
yum -y install wget
curl -L -b "oraclelicense=a" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz -O
tar xzf jdk-8u131-linux-x64.tar.gz
cd /opt/jdk1.8.0_131/
alternatives --install /usr/bin/java java /opt/jdk1.8.0_131/bin/java 2
alternatives --config java
alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_131/bin/jar 2
alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_131/bin/javac 2
alternatives --set jar /opt/jdk1.8.0_131/bin/jar