Skip to content

Instantly share code, notes, and snippets.

View wolfiestyle's full-sized avatar

wolfiestyle

  • Chile
View GitHub Profile
@wolfiestyle
wolfiestyle / test.asm
Created March 19, 2013 22:06
example asm code with function call
; example ASM code
; compile with 'nasm -f elf test.asm && gcc -m32 -o test test.o'
bits 32 ; use 32 bit architecture
global main ; declare 'main' funcion (called by the OS)
extern printf ; 'printf' from libc
; read-only variables
section .data
strDesu db "desu desu purrRRrRr %d", 10, 0 ; string, must end with 0, the 10 is "\n"
@wolfiestyle
wolfiestyle / gist:5008743
Created February 21, 2013 22:04
js functions to convert between hex string and rgb object colors
function hexToRgb(hex)
{
var res = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return res ? {
r: parseInt(res[1], 16),
g: parseInt(res[2], 16),
b: parseInt(res[3], 16)
} : null;
}
@wolfiestyle
wolfiestyle / gist:3932036
Created October 22, 2012 15:21
Declarative objects in Perl using closures
#!/usr/bin/perl
use strict;
sub create
{
my ($name, $age) = @_;
return {
get_age => sub { $age; },
set_age => sub { ($age) = @_; },
@wolfiestyle
wolfiestyle / gist:3907574
Created October 17, 2012 19:26
strange error in line 7
#!/usr/bin/perl
use strict;
sub test
{
open FP, "< $0" or die;
while (<FP>) # Modification of a read-only value attempted at ./test.pl line 7.
{
chomp;
print "w: $_\n";
@wolfiestyle
wolfiestyle / mandel.lua
Created October 3, 2012 18:45
an over-elaborate way of generating the mandelbrot fractal
#!/usr/bin/lua
-- complex number class
do
local _meta = {
__tostring = function(self)
return "(" .. self.re .. ", " .. self.im .. ")"
end,
__add = function(self, rhs)
return Complex(self.re + rhs.re, self.im + rhs.im)
end,
@wolfiestyle
wolfiestyle / gist:3790264
Created September 26, 2012 20:07
convert all links with class "post" to POST requests
$('a.post').click(function(ev) {
ev.preventDefault();
var param = $(this).attr('href').replace(/^\?/, '').split('&').map(function(p) { return p.split('='); });
$('<form method="POST" action="#">')
.append(param.map(function(e) { return '<input type="hidden" name="' + e[0] + '" value="' + e[1] + '" />'; }))
.appendTo('body').submit();
});
@wolfiestyle
wolfiestyle / Preferences.sublime-settings
Created September 19, 2012 01:08
my Sublime Text settings
{
"auto_match_enabled": false,
"close_windows_when_empty": true,
"color_scheme": "Packages/User/wolfie.tmTheme",
"ensure_newline_at_eof_on_save": true,
"fallback_encoding": "ISO-8859-1",
"font_face": "Dejavu Sans Mono",
"font_options":
[
"gray_antialias"
@wolfiestyle
wolfiestyle / polinomio.cpp
Created June 30, 2012 04:50
multiplicacion de polinomios en C++ basico
#include <iostream>
#include <algorithm>
#include <cassert>
enum
{
MAX_COEFF = 16,
};
struct polinomio
@wolfiestyle
wolfiestyle / setexplicit.lua
Created May 2, 2012 15:11
require explicit variable assign before usage on specified table
function setexplicit(table)
table = table or _G
setmetatable(table, {
declared = {},
__newindex = function(t, n, v)
getmetatable(t).declared[n] = true
rawset(t, n, v)
end,
__index = function(t, n)
if getmetatable(t).declared[n] then
@wolfiestyle
wolfiestyle / markov1.d
Created April 23, 2012 01:45
generates a random string from stdin text input using a Nth order markov chain
import std.stdio, std.array, std.string, std.conv, std.random;
enum { ORDER = 2, MAX_RESULT_WORDS = 20 }
void main()
{
uint[string][string] dict;
string[] prev;
foreach (line; stdin.byLine())
foreach (word; split(to!string(toLower(line))))