Skip to content

Instantly share code, notes, and snippets.

View MarcAstr0's full-sized avatar

Mario Castro Squella MarcAstr0

View GitHub Profile
@MarcAstr0
MarcAstr0 / checkRut.js
Last active August 24, 2017 22:04
JavaScript function to check whether a string is a valid Chilean ID number, also known as RUT (Rol Único Tributario) or RUN (Rol Único Nacional)
function checkRut(rut) {
var cleanRut = rut.replace(/[\.|-]/g, '');
var dv = cleanRut.substr(-1);
var rest = cleanRut.substr(0, cleanRut.length-1);
var digits = rest.split('').reverse().map(function(d, i) { return [(i%6)+2, parseInt(d)]; });
var sum = digits.map(function(x) { return x[0]*x[1]; }).reduce(function(x, y) { return x+y; });
var result = 11 - (sum % 11);
switch(result) {
case 11:
return (0 === dv);
@MarcAstr0
MarcAstr0 / bacon.pl
Created November 7, 2017 18:59
Prolog code to calculate the Bacon Number (or the "Six Degrees of Kevin Bacon" game)
%% Kevin Bacon movies
cast(['Kevin Bacon', 'Lori Singer', 'John Lithgow', 'Dianne Wiest']). %% Footloose (1984)
cast(['Tom Cruise', 'Jack Nicholson', 'Demi Moore', 'Kevin Bacon']). %% A Few Good Men (1992)
cast(['Tom Hanks', 'Bill Paxton', 'Kevin Bacon', 'Gary Sinise']). %% Apollo 13 (1995)
%% Tom Cruise movies
cast(['Tom Cruise', 'Kelly McGillis', 'Val Kilmer', 'Anthony Edwards']). %% Top Gun (1985)
cast(['Tom Cruise', 'Cuba Gooding Jr.', 'Renée Zellweger', 'Kelly Preston']). %% Jerry Maguire (1996)
cast(['Tom Cruise', 'Rebecca De Mornay', 'Joe Pantoliano', 'Richard Masur']). %% Risky Business (1983)
@MarcAstr0
MarcAstr0 / temperature.c
Created November 27, 2017 15:46
Simple library for converting temperatures from Celsius to Fahrenheit and vice versa.
#include "temperature.h"
#include <math.h>
float to_fahrenheit(float celsius) {
float fahrenheit;
fahrenheit = roundf( ( (celsius * (9.00f/5.00f)) + 32.00f ) * 100.00f ) / 100.00f;
return fahrenheit;
}

Keybase proof

I hereby claim:

  • I am marcastr0 on github.
  • I am marcastr0 (https://keybase.io/marcastr0) on keybase.
  • I have a public key ASCV0TzqAn9-ZDAaO4WWc2OSpakvaITR3EgvldAtkFk9UAo

To claim this, I am signing this object: