Skip to content

Instantly share code, notes, and snippets.

@sadikovi
sadikovi / APIManager.java
Created August 12, 2014 11:30
Bunch of Java classes that allow you to read a Google Calender and output all user's calenders/events in a structured way as json
package project1;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.net.URLEncoder;
@sadikovi
sadikovi / 2_MaxCounters.java
Last active August 29, 2015 14:06
Codility Lesson 2
class Solution {
public int[] solution(int N, int[] A) {
int[] counters = new int[N];
int max = 0;
int absMax = 0;
for (int i=0; i<A.length; i++) {
if (A[i] == N+1) {
if ((i < A.length-1 && A[i+1] != N+1) || (i==A.length-1)) {
absMax += max;
@sadikovi
sadikovi / 3_CountDiv.java
Last active August 29, 2015 14:06
Codility Lesson 3
class Solution {
public int solution(int A, int B, int K) {
return B/K - A/K + ((A % K == 0)?1:0);
}
}
@sadikovi
sadikovi / 5_Fish.java
Last active August 29, 2015 14:06
Codility Lesson 5
// simplier solution and neater
class Solution {
public int solution(int[] A, int[] B) {
int[] dFish = new int[A.length];
int di = -1;
int upstreamCount = 0;
for (int i=0; i<A.length; i++) {
if (B[i] == 1) {
dFish[++di] = A[i];
@sadikovi
sadikovi / 7_MaxDoubleSliceSum.java
Last active August 29, 2015 14:06
Codility Lesson 7
/*
We should travel the array twice.
For the first travel, we compute and record the maximum sub-array sum, which ends at each position.
At the second reverse travel, we compute and record the maximum sub-array sum, which starts at each position.
Finally, we combine two sub-arrays into one double slice, and find out the maximum sum.
*/
class Solution {
public int solution(int[] A) {
int[] a = new int[A.length];
@sadikovi
sadikovi / 8_Peaks.java
Last active August 29, 2015 14:06
Codility Lesson 8
class Solution {
public int solution(int[] A) {
int[] a = new int[A.length];
int peak = -1;
for (int i=0; i<A.length; i++) {
if (i > 0 && i < A.length-1)
if (A[i] > A[i-1] && A[i] > A[i+1])
peak = i;
a[i] = peak;
@sadikovi
sadikovi / 9_CountNonDivisible.java
Last active August 29, 2015 14:06
Codility Lesson 9
import java.util.HashMap;
class Solution {
public int[] solution(int[] A) {
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
HashMap<Integer, Integer> resmap = new HashMap<Integer, Integer>();
int[] res = new int[A.length];
for (int i=0; i<A.length; i++) {
int count = 1;
@sadikovi
sadikovi / 10_CommonPrimeDivisors.java
Last active August 29, 2015 14:06
Codility Lesson 10
class Solution {
public int solution(int[] A, int[] B) {
int pairs = 0;
for (int i=0; i<A.length; i++)
if (commonPrimeDivisors(A[i], B[i]))
pairs++;
return pairs;
}
@sadikovi
sadikovi / a_map_generator.js
Last active August 29, 2015 14:06
Generates two-dimensional map with paths ("2"s). The "1"s and "0"s - are blocks or walls
// i and j current coordinates of the point
// a is two-dimensional array of points
// n is rows number
// m is columns number
// point is a number: 0 - free, 1 - block, 2 - path
// directions:
// 0 - left
// 1 - up
// 2 - right
@sadikovi
sadikovi / obiee_writeback_execute.xml
Created September 26, 2014 09:09
OBIEE writeback xml files (one with PL/SQL merge, another with execute, therefore it is available to call those statements for OBI WB)
<?xml version="1.0" encoding="utf-8" ?>
<WebMessageTables xmlns:sawm="com.siebel.analytics.web/message/v1">
<WebMessageTable lang="en-us" system="WriteBack" table="Messages">
<WebMessage name="testExecute">
<XML>
<writeBack connectionPool="cp_logistics_write_back">
<insert> </insert>
<update> call execute_test() </update>
</writeBack>
</XML>