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
@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 / 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 / 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"
#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 / 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>
@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"
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
# app/models/puntos.rb
class Puntos < AR::Base
PUNTOS_ALL_KEY = "all_puntos".freeze
after_save :expire_cache
after_destroy :expire_cache
# Guarda un arreglo de hashes con el JSON pa mandar.
def self.all_cached
Rails.cache.fetch(PUNTOS_ALL_KEY) do
//Convierte un numero N en base B a decimal
public int toDecimal(int n, int b)
{
int result=0;
int multiplier=1;
while(n>0)
{
result+=n%10*multiplier;
multiplier*=b;
set<int>f,s,tmp;
set_intersection(all(f),all(s), inserter(tmp, tmp.begin()));