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
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 |
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
/* 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 |
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
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" |
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
#include <iostream> | |
#include <cstdio> | |
#include <algorithm> | |
#include <cstdlib> | |
#include <vector> | |
#include <queue> | |
#include <iterator> | |
#include <map> | |
#include <set> |
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
#include <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
#define MAXN 100005 | |
#define D(x) cout << #x " is " << x << endl |
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
#!/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" |
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
# 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 |
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
rake () { | |
if [ -e bin/rake ] | |
then | |
bin/rake $@ | |
elif [ -e Gemfile ] | |
then | |
bundle exec rake $@ | |
else | |
command rake $@ | |
fi |
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
# http://stdout.heyzap.com/2013/04/08/surfacing-interesting-content/ | |
class PopularStream | |
attr_reader :name, :epoch, :max_items | |
# 2.5 * half_life (in days) years from now | |
DEFAULT_EPOC = Date.new(2017, 4, 27).to_time.to_i | |
HALF_LIFE = 1.day.to_i | |
def self.redis | |
RedisConfig.client(:trending_stuff) |
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 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 |