Skip to content

Instantly share code, notes, and snippets.

View nhocki's full-sized avatar
💭
I may be slow to respond.

Nicolás Hock-Isaza nhocki

💭
I may be slow to respond.
View GitHub Profile
int n;
inline int index(int i){ if (i > 0) return i; else return n - i; }
inline int no(int i){ return -1*i; } //negation of a node
@nhocki
nhocki / tarjan.cc
Created February 24, 2015 01:57
Tarjan Algorithm in C++
/* Complexity: O(E + V)
Tarjan's algorithm for finding strongly connected
components.
*d[i] = Discovery time of node i. (Initialize to -1)
*low[i] = Lowest discovery time reachable from node
i. (Doesn't need to be initialized)
*scc[i] = Strongly connected component of node i. (Doesn't
need to be initialized)
*s = Stack used by the algorithm (Initialize to an empty
@nhocki
nhocki / nhocki_emacs.pp
Created December 12, 2014 08:22
My emacs manifest for Boxen
class people::nhocki::emacs {
notice("Setting up ${::boxen_user}'s emacs repo")
package { 'cask':
ensure => present
}
$home = "/Users/${::boxen_user}"
$src = "${home}/src"
$emacs = "${src}/emacsdotd"
@nhocki
nhocki / fav_seq.cc
Created November 20, 2014 04:23
Favorite Seqence for HackerRank
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <queue>
#include <iterator>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#define MAXN 100005
#define D(x) cout << #x " is " << x << endl
@nhocki
nhocki / docker.sh
Created November 19, 2014 03:00
Docker file that Jenkins should run.
#!/usr/bin/env sh
# Build the image to be used for this job.
IMAGE=$(docker build . | tail -1 | awk '{ print $NF }')
echo "Image $IMAGE"
# Build the directory to be mounted into Docker.
MNT="$WORKSPACE"
echo "Mounting on $MNT"
@nhocki
nhocki / time_range_validator.rb
Last active August 29, 2015 14:09
Time Range Validator
# This validator makes it easy to force a date to be after or before another.
#
# validate :end_date, time_range: { after: :start_date }
# validate :created_at, time_range: { before: :deleted_at }
#
# You can pass messages for each type of comparisson.
#
# validate :end_date, time_range: { after: :start_date, after_message: "Foo" }
# validate :end_date, time_range: { after: :start_date, message: "Default message" }
class TimeRangeValidator < ActiveModel::EachValidator
@nhocki
nhocki / -
Created November 11, 2014 01:26
rake () {
if [ -e bin/rake ]
then
bin/rake $@
elif [ -e Gemfile ]
then
bundle exec rake $@
else
command rake $@
fi
@nhocki
nhocki / office_hours.rb
Created October 10, 2014 19:53
Disable something if not on a specific time-frame // day
def office_hours?
Time.use_zone('Pacific Time (US & Canada)') do
# window = Time.zone.parse("2014-04-30")
now = Time.zone.now
start, finish = Time.zone.parse('9:30'), Time.zone.parse('16:30')
now.between?(start, finish) # && now.yday == window.yday
end
end