Skip to content

Instantly share code, notes, and snippets.

@indranil32
indranil32 / Sorting.groovy
Last active August 31, 2019 19:49
Sorting
def arr = [2,1,7,9,8,6,4,5,10,3]
// initial state of the array
println arr
// bubble up the largest element for each increment of the outer loop
def bubbleSort(arr) {
for (int i = 0 ; i < arr.size() - 1; i++) {
for (int j = 0 ; j < (arr.size() - i -1 ); j++) {
if (arr[j] > arr[j+1]){
def tmp = arr[j]
@indranil32
indranil32 / matrix_rotation.groovy
Created August 30, 2019 17:07
Square Matrix Rotation
def matrix = [[ 1, 2, 3, 4, 17],
[ 5, 6, 7, 8, 18],
[ 9,10,11,12, 19],
[13,14,15,16, 20],
[21,22,23,24, 25]]
/* Output
[21, 13, 9, 5, 1]
[22, 14, 10, 6, 2]
[23, 15, 11, 7, 3]
[24, 16, 12, 8, 4]
@indranil32
indranil32 / twoSum4SortedArray.groovy
Created August 30, 2019 17:09
o(n) implementation of two sum for sorted array
def arr2 = [1,3,4,5,9]
def sum = 16
def twoSum(arr, sum) {
if (arr[0] > sum) return;
if (arr[1] > sum || arr[1] + arr[0] > sum) return;
int i = 0;
int j = arr.size() -1
for ( ; i < j ; ) {
if ((arr[i] + arr[j]) > sum) {
@indranil32
indranil32 / graph.groovy
Created August 31, 2019 09:07
Graph Implementation
int vertices = 4
int edges = 5
int[][] edgeWeightArr = [[1,2,7],[1,4,6],[4,2,9],[4,3,8],[2,3,6]]
// LIFO
class Stack {
int [] arr
int top = 0
public Stack(int size) {
arr = new int[size]
}
@indranil32
indranil32 / dynamic_programming.groovy
Last active September 20, 2019 09:47
Dynamic Programming Samples
// max sum of non-consecutive numbers
def arr = [3, 1, 4, 2, 5, 10 ]
//def arr = [4,1,1,4,2,1]
//def arr = [2,5,3,1,7]
def map = [:]
// non dynamic solution - brute force
for (int i = 0 ; i < arr.size() ; i++) {
def sum = arr[i]
def op = [arr[i]]
@indranil32
indranil32 / Android-Emulator-on-AWS-EC2.txt
Created December 5, 2019 18:21 — forked from atyachin/Android-Emulator-on-AWS-EC2.txt
Installing and running Android Emulator on Amazon AWS EC2 (Ubuntu 16.04 / m5.xlarge)
Steps for installing the Android Emulator from EC2 console:
-----------------------------------------------------------
sudo apt install default-jdk
wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
unzip sdk-tools-linux-4333796.zip -d android-sdk
sudo mv android-sdk /opt/
export ANDROID_SDK_ROOT=/opt/android-sdk
echo "export ANDROID_SDK_ROOT=/opt/android-sdk" >> ~/.bashrc
echo "export PATH=$PATH:$ANDROID_SDK_ROOT/tools" >> ~/.bashrc
re-login
@indranil32
indranil32 / index.js
Created December 7, 2019 10:51
Node JS + webdriverio + appium + screenshots
const wdio = require("webdriverio");
const assert = require("assert");
const fs = require('fs');
const opts = {
port: 4723,
capabilities: {
platformName: "Android",
platformVersion: "7.1",
deviceName: "Android Emulator",
npm login -registry=http://nexus.you.love/repository/nexus-npm/
npm publish -registry=http://nexus.you.love/repository/nexus-npm/
def versionMajor = 3
def versionMinor = 0
def versionPatch = 0
def versionBuild = 0 // get from Jenkins -PversionBuild=${env.BUILD_NUMBER}
android {
defaultConfig {
versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
stage('Upload APK to internal Nexus') {
environment {
// the creds your Jenkins use to communicate with your nexus
JENKINS_USER_CREDS = credentials('jenkins-user-password')
ENV_NAME = "${env.BRANCH_NAME}"
}
when {
anyOf {
// choose what kinds of builds you want to arhive in your nexus
branch 'develop';