Skip to content

Instantly share code, notes, and snippets.

View wolfiestyle's full-sized avatar

wolfiestyle

  • Chile
View GitHub Profile
@wolfiestyle
wolfiestyle / gist:2039291
Created March 14, 2012 20:30
assign all views on R.id to member variables of the same name using reflection
/** assign all views on R.id to member variables of the same name using reflection */
private void findAllViews()
{
Field[] r_fields = R.id.class.getDeclaredFields();
for (Field f: r_fields)
{
String name = f.getName();
Field v;
try
{
@wolfiestyle
wolfiestyle / Makefile
Created March 28, 2012 00:15
basic makefile for D language
# basic makefile for D language - made by darkstalker
DCC = dmd
DFLAGS = -w
LIBS =
SRC = $(wildcard *.d)
OBJ = $(SRC:.d=.o)
OUT = $(shell basename `pwd`)
.PHONY: all debug release profile clean
@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))))
@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 / 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 / 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 / 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 / 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: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 / 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) = @_; },