Skip to content

Instantly share code, notes, and snippets.

View amosrivera's full-sized avatar

Amós Rivera amosrivera

  • Managua, Nicaragua
View GitHub Profile
def get_serve_pattern(queue, barbers)
min = barbers.min
freq = barbers.map { |b| (b / min).ceil }
count = 0
0.upto(queue).each do |n|
puts "count is #{count}"
count += 1
barbers.each_with_index do |b, i|
if n % freq[i] == 0
require 'pry'
file = File.new(ARGV[0], "r")
# delete current output file
if File.exist?("output.txt")
File.delete("output.txt")
end
# number of cases
cases = file.gets
@amosrivera
amosrivera / functions.js
Last active January 3, 2016 07:29
Returns an array of the previous 7 days.
// Returns an arrary with the name of the previous seven days (?)
var getPreviousWeek = function(){
// get day index monday => 0, tuesday => 1, ...
var today = (new Date().getDay()-1);
//0 index based array, monday => 0, tuesday => 1 and so on
var days = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
// range returns [1, 2, 3, 4, 5, 6, 7]
@amosrivera
amosrivera / kui-login.sh
Created November 14, 2013 15:30
Kui Login
cd /usr/share/sounds/ubuntu/stereo/
sudo mv desktop-login.ogg desktop-login.ogg.old
sudo wget "https://dl.dropboxusercontent.com/s/i75iiy70gomutka/desktop-login.ogg?dl=1&token_hash=AAGc5mdNY5DqejjSoiJNGxiU2gvnuTSz-M8akFxucX9KKA"
sudo mv desktop-login.ogg\?dl=1\&token_hash=AAGc5mdNY5DqejjSoiJNGxiU2gvnuTSz-M8akFxucX9KKA desktop-login.ogg
/**
* Created with IntelliJ IDEA.
* User: paulomcnally
* Date: 10/30/13
* Time: 8:53 PM
* To change this template use File | Settings | File Templates.
*/
var crypto = require('crypto');
var mssql = require('mssql');
/*
String Calculator
1- The program can take 0, 1 or 2 numbers and will
return their sum, (for an empty string it will return 0)
for example "" or "1" or "1,2" -> 0, 1, 3
2- Allow the Add method to handle an unknown amount
of numbers
@amosrivera
amosrivera / flatten.js
Created August 30, 2013 00:54
Flatten array. No matter the depth.
var flatten = function(){
var reduce = function (array) {
return array.reduce(function(r,e){
return r.concat( (e instanceof Array) ? reduce(e) : e );
},[]);
}
return reduce(Array.prototype.slice.call(arguments));
}
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
@amosrivera
amosrivera / format_date.php
Created October 16, 2012 09:07
Format dates in Spanish.
function format_date($date,$format) {
$es_months = array("Ene", "Abr", "Ago", "Dic");
$en_months = array("Jan", "Apr", "Aug", "Dec");
$timestamp = strtotime(str_replace($es_months,$en_months,$date));
return str_replace($en_months,$es_months,date($format,$timestamp));
}
@amosrivera
amosrivera / new_bashrc.sh
Created August 12, 2012 00:33 — forked from josephwecker/new_bashrc.sh
Replace .bashrc, .bash_profile, .profile, etc. with something much more clean, consistent, and meaningful. Now a repo: https://github.com/josephwecker/bashrc_dispatch
#!/bin/bash
# License: Public Domain.
# Author: Joseph Wecker, 2012
#
# -- DEPRICATED --
# This gist is slow and is missing .bashrc_once
# Use the one in the repo instead! https://github.com/josephwecker/bashrc_dispatch
# (Thanks gioele)
#
# Are you tired of trying to remember what .bashrc does vs .bash_profile vs .profile?