Skip to content

Instantly share code, notes, and snippets.

@Madrigal
Madrigal / Elevator saga
Last active August 29, 2015 14:14
My strategy for elevator saga http://play.elevatorsaga.com/
// The only small improvement from challange #3 was
// manipulating the elevator light
{
init: function(elevators, floors) {
elevators.forEach(function(elevator){
elevator.on("floor_button_pressed", function(floorNum) {
elevator.goToFloor(floorNum);
});
@Madrigal
Madrigal / next_quincena.js
Created October 1, 2015 13:21
A snippet to know when is the next pay day
// Snippet to know when is the next pay day (quincena)
// The rules are:
// -Pay day is on the 15th and the last day of the month
// -- If that day is not a weekday (Mon-Fri) pay day falls on the previous Friday
// Of course, without additional effort this won't take into consideration holidays
// January is 0 and so on
var daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
function isLeapYear(year) {
@Madrigal
Madrigal / print_matrix.c
Last active December 21, 2015 23:59
[WTF] Unexpected behavior in C, prints full matrix, no warnings
/*
WTF behavior in C. At least not what I expected.
Prints full matrix with just one call to the index
*/
#include "stdio.h"
#include "stdlib.h"
void print_square_matrix(int* matrix, int size);
@Madrigal
Madrigal / gran_7
Created November 16, 2013 23:33
Script to solve the problem described in http://orsaibonsai.com/blog/post/gran_7 XX/XXX + XX/XX = 7 With numbers from 1 to 9, fill all the slots without repeating numbers to sum 7
#! /usr/bin/env python
# // XX/YYY + XX/YY = 7
import random
numbers = [1,2,3,4,5,6,7,8,9]
res = 0
target = 7
def pop_random (num):
res = []
@Madrigal
Madrigal / kindle.sh
Created January 14, 2014 23:34
Send files to your Amazon Kindle via the Command Line Interface.
# Command line utility to send attachments to your kindle
# It supports sending a PDF in both regular form and with the convert option
# and sending to the regular (@kindle.com) or free Kindle mail (@free.kindle.com)
# The only argument it has is the name of the file to send. It will detect if
# it is a pdf and treat it accordingly.
## Preferences
# If true, send one version with pdf as-is, another with 'convert' subject
# else, just send the pdf version