Skip to content

Instantly share code, notes, and snippets.

View svpino's full-sized avatar
🏠
Working from home

Santiago Valdarrama svpino

🏠
Working from home
View GitHub Profile
@svpino
svpino / RotatingMatrix90DegreesInPlace.java
Last active June 8, 2018 11:00
Programming challenge: rotating a matrix 90 degrees in place
// Programming challenge: rotating a matrix 90 degrees in place
// Original post: https://blog.svpino.com/2015/05/10/programming-challenge-rotating-a-matrix-90-degrees-in-place
public class RotatingMatrix90DegreesInPlace {
private static int[][] matrix = {
{ 1, 2, 3, 4 },
{ 5, 6, 7, 8 },
{ 9, 10, 11, 12 },
{ 13, 14, 15, 16 }
@svpino
svpino / Problem4.java
Created May 12, 2015 23:49
Problem 4 in "Five programming problems every Software Engineer should be able to solve in less than 1 hour"
import java.util.Arrays;
import java.util.Comparator;
// Solution to Problem 4 posted in "Five programming problems every Software Engineer should be able to solve in less than 1 hour"
// Original post: https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
public class Main {
private static Integer[] VALUES = { 5, 2, 1, 9, 50, 56 };
public static void main(String[] args) {
@svpino
svpino / Problem5.java
Created May 12, 2015 23:50
Problem 5 in "Five programming problems every Software Engineer should be able to solve in less than 1 hour"
import java.util.ArrayList;
// Solution to Problem 5 in "Five programming problems every Software Engineer should be able to solve in less than 1 hour"
// Original post: https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
public class Main {
private static int TARGET_SUM = 100;
private static int[] VALUES = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
static ArrayList add(int digit, String sign, ArrayList branches) {
@svpino
svpino / MergingOverlappingIntervals.java
Last active August 29, 2015 14:21
Programming challenge: Merging overlapping intervals
import java.util.Arrays;
import java.util.Comparator;
// Programming challenge: Merging overlapping intervals
// Original post: https://blog.svpino.com/2015/05/17/programming-challenge-merging-overlapping-intervals
public class MergingOverlappingIntervals {
private static Integer[][] intervals = {
{1, 3},
{2, 6},
@svpino
svpino / PositionOfTheElement.java
Last active August 29, 2015 14:21
Programming challenge: the position of the element
// Programming challenge: the position of the element
// Original post: https://blog.svpino.com/2015/05/24/programming-challenge-the-position-of-the-element
public class Main {
private static int[] array = { 1, 3, 5, 6 };
// Solution using a sequential search - O(n)
private static int sequential(int target) {
if (target < array[0]) {
return 0;
@svpino
svpino / pipeline_example.py
Created May 18, 2015 23:49
Google App Engine Pipeline API Example
# This pipeline sums up a bunch of values. That simple.
class SumPipeline(pipeline.Pipeline):
def run(self, *values):
return sum(values)
# This pipeline takes care of computing the score of one specific player
class PlayerScorePipeline(pipeline.Pipeline):
def run(self, player, level):
# Let's call our remote REST API to return the score
# of this player on the supplied level.
@svpino
svpino / towersOfHanoi.java
Last active October 1, 2017 17:38
Programming challenge: towers of Hanoi
// Programming challenge: towers of Hanoi
// Original post: https://blog.svpino.com/2015/06/07/programming-challenge-towers-of-hanoi
public class Main {
private static int NUMBER_OF_DISKS = 3;
public static void towersOfHanoi(int n, String rod1, String rod2, String rod3) {
if (n == 1) {
System.out.println("* Move disk from " + rod1 + " to " + rod3);
}
@svpino
svpino / last_monday.sql
Created December 18, 2015 15:34
How to determine last Monday's date in BigQuery
select date(date_add(current_date(), if(dayofweek(current_date()) = 1, -6, -(dayofweek(current_date()) - 2)), "DAY"))
@svpino
svpino / last_five_business_days.sql
Created December 18, 2015 15:35
How to determine last 5 business days in BigQuery
select date
from
(select date_add(current_date(), -1, "DAY") as date),
(select date_add(current_date(), -2, "DAY") as date),
(select date_add(current_date(), -3, "DAY") as date),
(select date_add(current_date(), -4, "DAY") as date),
(select date_add(current_date(), -5, "DAY") as date),
(select date_add(current_date(), -6, "DAY") as date),
(select date_add(current_date(), -7, "DAY") as date)
where dayofweek(date) >= 2 and dayofweek(date) <= 6