Skip to content

Instantly share code, notes, and snippets.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@phyous
phyous / MinHopsNovel.java
Last active October 27, 2016 05:43
Calculating Minimum number of hops through an array
import java.util.ArrayList;
import java.util.List;
public class MinHopsNovel {
public static List<Integer> minHops(List<Integer> input) {
List<Integer> ret = new ArrayList<>();
if (input.size() == 0) return ret;
@phyous
phyous / Cib.java
Created July 20, 2016 19:22
Chained interface builder with inheritance
package com.phyous.cib;
public class Cain {
public static void main(String[] args) {
B b = new B.Builder().
parent(
new A.Builder()
.m1(1)
.m2(2)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/orange_hn"
>
<TextView
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
public class MyActivity extends Activity {
@Override
@phyous
phyous / Trie.java
Created June 7, 2014 19:22
Having fun with Tries
package com.other.rand;
import java.util.ArrayList;
import java.util.List;
/*
Let's create a trie data structure and run some tests on it
Documentation:
- http://en.wikipedia.org/wiki/TrieTest
- http://www.geeksforgeeks.org/trie-insert-and-search/
public static boolean oneEditAppart(String a, String b) {
int edits = 0;
if (a == null || b == null || Math.abs(a.length() - b.length()) > 1) { // Strings more than 1 in size difference
return false;
} else if (a.length() == b.length()) { // Strings same size, check for 0 or >1 replacements
for (int i = 0; i < a.length(); i++) {
if (a.charAt(i) != b.charAt(i)) {
if (++edits > 1) return false;
}
}
@phyous
phyous / CalculateWater.java
Last active August 29, 2015 14:00
CalculateWater
/**
* Trapping Water
*
* A one-dimensional container is specified by an array of
* n nonnegative integers, specifying the eight of each
* unit-width rectangle. Design an algorithm for computing
* the capacity of the container.
*
* Ex: (X = Occupied, ▤ = Water)
*
def pascalsTriangle(n)
return [] if n < 0
return [1] if n == 0
ret = Array.new(n, []).map.each_with_index {|a, i| a = Array.new(i+1,1)}
(1..n-1).each do |y|
(0..y).each do |x|
idy1 = y - 1
idx1 = x - 1
@phyous
phyous / gist:7983685
Created December 16, 2013 07:56
The world's simplest twitter client
#!/usr/bin/env ruby
########################
# The world's simplest twitter client
# 1- Get an API key form https://dev.twitter.com with read/write access, enter details below @'ENTER_HERE'
# 2- gem install twitter
# 3- ./post
# 4- Start posting
########################
require "rubygems"