Skip to content

Instantly share code, notes, and snippets.

View Mithrandir0x's full-sized avatar

Oriol López Sánchez Mithrandir0x

View GitHub Profile
@Mithrandir0x
Mithrandir0x / gist:4351696
Created December 21, 2012 09:21
Levenshtein and DTW stoopidities
A LGO R I S M I C A
A V A N Ç A D A
1 1 1 0 0 1 _ 0 1
_ _ _ _ 0 0 1 _ _
_ _ 1 1 1 _ _ _ _
1 1 1 1 1 1 1 0 1
1 1 1 1 0 0 0 1
@Mithrandir0x
Mithrandir0x / Console
Created November 23, 2012 17:37
Segmentation Fault with nested function in C
$ gcc -c -g nested_function_segfault.c -ansi -pedantic -O -Wall -Wno-unused-result
nested_function_segfault.c: In function ‘polinomi_d’:
nested_function_segfault.c:18:5: warning: ISO C forbids nested functions [-pedantic]
nested_function_segfault.c: In function ‘main’:
nested_function_segfault.c:33:1: warning: control reaches end of non-void function [-Wreturn-type]
$ gcc nested_function_segfault.o -o nested_function_segfault.exe -lm
$ ./nested_function_segfault.exe
Segmentation fault (core dumped)
@Mithrandir0x
Mithrandir0x / f_ptr_ex.c
Created November 16, 2012 12:14
Example of function pointers in C
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define PI 3.141592653589793
double f_a(double x) { return x*x + sin(x) - PI; }
typedef double (*MATH_FUNCTION)(double);
@Mithrandir0x
Mithrandir0x / gist:3683228
Last active October 10, 2015 11:27
Function for traversing a matrix over its diagonals
function diagonalTraverse(m, fn)
{
// This only works for rectangular or square
// form matrices. So no rows of variable sizes!
if ( m && m.length > 0 && m[0].length > 0 )
{
var i = 0, j = 0,
ci = null, cj = null,
M = m[i].length, // # of columns
@Mithrandir0x
Mithrandir0x / gist:3639232
Created September 5, 2012 16:15
Difference between Service, Factory and Provider in AngularJS
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
@Mithrandir0x
Mithrandir0x / gist:3619682
Created September 4, 2012 10:22
"Example" style used in Bootstrap documentation.
.bs-docs-example
{
position: relative;
margin: 15px 0;
padding: 39px 19px 14px;
background-color: white;
border: 1px solid #DDD;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
@Mithrandir0x
Mithrandir0x / gist:3612821
Created September 3, 2012 19:49
When Rapidshare links get stubborn on plowshare, who'll you call?
l_links.forEach(function(url){ // \.(...)\|\| // .$1||
$.ajax({
url: url,
success: function(data, state, jqxhr){
console.log(data.split('location="')[1].split('"')[0]);
}
});
});
@Mithrandir0x
Mithrandir0x / gist:3205753
Last active October 7, 2015 18:18
FOR Loop notation
// I know it adds another variable, but still, I find it fuzzy :3
for ( var i = 0, file = files[0] ; i < files.length ; i++, file = files[i] ){}
{
"uses": ["LaAventuraOriginal.messages.es"],
"actors": ["freak", "punk", "nerd", "master"],
"gameDirector": "master",
"partyGold": 200,
"npcs": {
"goblin": {
"names": "@goblin_names",
"pluralise": "@goblin_num",
"attributes": {
@Mithrandir0x
Mithrandir0x / Made of Code.tmTheme
Created February 29, 2012 16:42
Theme "Made of Code" for SublimeText2
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>comment</key>
<string>mkdynamic</string>
<key>name</key>
<string>Made of Code</string>
<key>settings</key>
<array>