This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Problem: Find # of occurrences of a substring in a given input string | |
Example Output: | |
Test string: abcdabceabcfabcabcd | |
Substring count for abc:5 | |
Substring count for abcd:2 | |
*/ | |
public class CountSubs { | |
public static void main(String[] args) { | |
String testString = "abcdabceabcfabcabcd"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################ | |
# Push notifications script | |
############################ | |
read -d '' String <<"EOF" | |
require "net/https" | |
require "socket" | |
url = URI.parse("https://api.pushover.net/1/messages.json") | |
req = Net::HTTP::Post.new(url.path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto lo | |
iface lo inet loopback | |
iface eth0 inet dhcp | |
auto wlan0 | |
allow-hotplug wlan0 | |
iface wlan0 inet manual | |
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf | |
iface default inet dhcp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id":"Barack Obama\tPERSON", | |
"description":"Barack Obama", | |
"image":null, | |
"type":"entity", | |
"children":[ | |
{ | |
"relationshipName":"tweetedBy", | |
"values":[ | |
{ |
OlderNewer