Skip to content

Instantly share code, notes, and snippets.

View SH4DY's full-sized avatar

Ramon SH4DY

View GitHub Profile
version: 0.2
env:
secrets-manager:
SONAR_TOKEN: prod/sonar:SONAR_TOKEN
SONAR_HOST_URL: prod/sonar:SONAR_HOST_URL
variables:
SourceBranch: ""
DestinationBranch: ""
IMAGE_REPO_NAME: "app-container-repo"
IMAGE_TAG: "Latest"
import AppDispatcherInstance = require('../dispatcher/AppDispatcher');
import Events = require('events');
import React = require('react');
import AppDispatcher = require("../dispatcher/AppDispatcher");
//This is just an alias for the interface AppDispatcher.AppPayload
import Payload = AppDispatcher.AppPayload
import ActionIdentifier = AppDispatcher.ActionIdentifier
import Interfaces = require('../Tree/Interfaces')
@SH4DY
SH4DY / setBetween.java
Created May 31, 2015 19:27
Given an integer n and two indexes i, j s.t. i >= j. return a integer where all the bits between positions i and j (both inclusive) are set to 1. The bits outside of this range shall not be modified.
/*
Given an integer n and two indexes i, j s.t. i >= j.
return a integer where all the bits between positions i and j (both inclusive)
are set to 1. The bits outside of this range shall not be modified.
*/
//Comments assuming 8 bit numbers
//Goal is to make a mask with 1's at positions j through i
public static int setBetween(int n, int i, int j){ //n = 00010000, i = 3, j = 1
@SH4DY
SH4DY / Inflight.java
Created May 12, 2015 07:39
In-Flight Entertainment. Knapsack with only 2 integer values. https://www.interviewcake.com/question/inflight-entertainment
//We can do this with only one loop
//thanks to the fact that we are looking for
//EXACTLY 2 movies which match the length.
//Duplicates are not being counted
//as we check for a hit FIRST and then put the
//value of the first movie into the map.
public static boolean isTwoMovies(int fl, int[] ml){
HashMap<Integer, Boolean> hm = new HashMap<Integer, Boolean >();
@SH4DY
SH4DY / RomanConversion.java
Created April 8, 2015 20:44
Roman number conversion, following the rules: Symbols are placed from left to right in order of value, starting with the largest. However, in a few specific cases,[2] to avoid four characters being repeated in succession (such as IIII or XXXX) these can be reduced using subtractive notation as follows:[3][4] the numeral I can be placed before V …
public class RomanConversion {
public static void main(String[] args){
System.out.println(toRoman(1904));
}
public static String toRoman(int x){
StringBuilder sb = new StringBuilder();
String number = x + "";
@SH4DY
SH4DY / forkJoin.java
Last active October 10, 2016 02:12
Find the greatest number in an array with a multi-threaded fork/join approach
/**
* Find the greatest number in an array with a multi-threaded fork/join approach.
*
* This is a simple recursive divide&conquer approach to search through a list
* and return the max-element. It is using a subclass of java.util.concurrent.ForkJoinTask
* (namely RecursiveTask<V>).
*
* Theoretical aspect: Amdahl's Law.
* Possible speedup with n processors: S(n) = 1 / (B + 1-B*(1/n))
* where B is the fractal of the programm which can only be
@SH4DY
SH4DY / permutationPalindrome.java
Created April 2, 2015 19:25
Give an algorithm to decide whether a given string or ANY of its permutations is a Palindrome. There is an O(n) algorithm for this problem!
/**
* Decide whether a given string or ANY
* of its permutations is a Palindrome.
*
* The given solution works in O(n). Building the parity map
* takes n steps, iterating through the map takes
* not more than n steps (size of the alphabet).
* Space consumption: Map with the size of the alphabet. (constant)
* @param str
* @return
@SH4DY
SH4DY / swap.java
Last active October 10, 2016 02:13
Swap two numbers in-place ==> without using a temp variable
//This method works only with integers
int a = 5;
int b = 7;
a = a-b; //diff. a = -2
b = a+b; // b = 5
a = b-a; // a = 7
//This method relies on bit manipulation and does not depend on the number format
int c = 3;
@SH4DY
SH4DY / parentheses.java
Created March 22, 2015 11:13
. A common problem for compilers and text editors is determining whether the parentheses in a string are balanced and properly nested. For example, the string ((())())() contains properly nested pairs of parentheses, which the strings )()( and ()) do not. Give an algorithm that returns true if a string contains properly nested and balanced paren…
//return -1: correct parentheses
//return n: Position of first offending bracket
public static int parantheses(char[] chrs){
Stack s = new Stack();
int i = 0;
for(;i<chrs.length;i++){ //Checks for erroneous chars omitted
char c = chrs[i];
@SH4DY
SH4DY / productExceptIndexDP.java
Last active October 10, 2016 02:13
/*You have an array of integers, and for each index you want to find the product of every integer except the integer at that index. Write a function get_products_of_all_ints_except_at_index() that takes an array of integers and returns an array of the products.*/ Greedy/DP approach
/*You have an array of integers, and for each index you want to find the product
of every integer except the integer at that index.
Write a function get_products_of_all_ints_except_at_index() that takes an array
of integers and returns an array of the products.*/
public static int[] get_products_of_all_ints_except_at_index_dp(int[] arr){
//build front
int[] front = new int[arr.length];
front[0] = 1;
for(int i = 1; i < arr.length; i++){