Skip to content

Instantly share code, notes, and snippets.

View rainiera's full-sized avatar

Rainier Ababao rainiera

View GitHub Profile

Keybase proof

I hereby claim:

  • I am rainiera on github.
  • I am rainiera (https://keybase.io/rainiera) on keybase.
  • I have a public key whose fingerprint is DC11 1E9D 7F57 B3F9 6340 8914 C246 9D53 5B5A 8553

To claim this, I am signing this object:

@rainiera
rainiera / PointDistance.java
Created February 19, 2015 22:22
example of PointDistance class for "KClosestPoints" problem
class PointDistance implements Comparable<PointDistance> {
Point p;
double dist;
public PointDistance(Point p, double dist) {
this.p = p;
this.dist = dist;
}
public int compareTo(PointDistance other) {
@rainiera
rainiera / TripleDuplicates.java
Created February 20, 2015 17:57
A method that returns an ArrayList of Strings that contain more than three of the same letter (case-insensitive), for the Names class of the NameSurfer project.
/**
* Returns an ArrayList of Strings of names that contain three or more
* of the same letter.
* @return A list of the names that contain three or more of the same letter.
*/
public ArrayList<String> tripleDuplicates() {
ArrayList<String> tripleDuplicates = new ArrayList<String>();
for (NameRecord name : this.names) {
HashMap<Character, Integer> map = new HashMap<Character, Integer>();
// I don't want case-sensitive letter frequencies
import java.util.HashSet;
import java.util.Random;
/*
* Given a string, write a function that returns the string, unaltered.
*/
public class StringString {
@rainiera
rainiera / gist:bfa75fc406c50920d24c
Last active August 29, 2015 14:18
Set implementation comparison
* (time in seconds)
*
* Title kb Total Distinct
*
* The Cat In The Hat 7 504 1622
* SortedSet time: 0.0343
* UnsortedSet time: 0.0169
* Java HashSet time: 0.0128
* Java TreeSet time: 0.0141
*
@rainiera
rainiera / gist:0a67c7aaad4c1c19445b
Created April 30, 2015 01:24
HPriorityQueue.java
public class HPriorityQueue<E extends Comparable<E>> {
private PQNode<E> first;
private PQNode<E> last;
private int size;
public HPriorityQueue() {
first = null;
last = null;
size = 0;
@rainiera
rainiera / factorial.c
Created September 3, 2015 03:15
Rad factorial algorithm
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
int factorial(int n) {
int ans[200]; // answer can have a max of 200 digits.
int temp, // <- carry
m, // <- ones place of the prod, to put in the array
prod, // product of the current digit
#include "mpi.h"
#include <stdio.h>
int main(int argc, char *argv[]) {
MPI_Init(&argc, &argv);
int rank;
int size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
int slice = 45200/32;
#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
/*
* Each process computes random number
* Root process finds and prints the maximum generated value
* Have each process print its value
*
# Vim
git clone https://github.com/amix/vimrc.git ~/.vim_runtime
sh ~/.vim_runtime/install_awesome_vimrc.sh
# Zsh
apt-get install -y zsh git-core
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"