Skip to content

Instantly share code, notes, and snippets.

View weapp's full-sized avatar
💸

Manuel Albarran weapp

💸
View GitHub Profile
@weapp
weapp / install.sh
Last active December 12, 2015 04:49 — forked from fenprace/install.sh
#!/bin/sh
sudo mv /usr/bin/xdg-open /usr/bin/xdg-open.bak
sudo curl https://gist.github.com/weapp/4717249/raw/16b3ce7ae4c4e63162ca0d9e47b2805d410bfa14/xdg-open.rb -o /usr/bin/xdg-open
sudo chmod a+x /usr/bin/xdg-open
@weapp
weapp / log_queue.py
Created February 10, 2013 22:55
Collection for store a degradable history
from collections import Iterable
import numpy as np
import math
class LogQueue(object):
"""Collection for store a degradable history"""
def __init__(self, size=5, depth=1):
super(LogQueue, self).__init__()
self.items = []
# Usage: redis-cli publish message hello
require 'sinatra'
require 'redis'
conns = []
get '/' do
erb :index
end
require 'rest_client'
require 'json'
require 'pp'
COUCHDB = "http://localhost:5984/dbname"
filters_doc = {
"_id" => "_design/app",
"filters" => {
"people"=> "function(doc, req) { return doc.type == 'person' }"
# http://www.rubytapas.com/episodes/7-Constructors
class RpsMove
def self.new(move)
@cache ||= {}
@cache[move] ||= super(move)
end
def initialize(move)
@move = move
require "ostruct"
obj = OpenStruct.new(a: "a", b: "b", to_ary: ["a", "b"] )
a, b = obj
puts "a: #{a}"
puts "b: #{b}"
obj = OpenStruct.new(a: "a", b: "b")
class Foo
class << self
def cls_method
"cls_method"
end
end
def ins_method
self.class.cls_method
end
// ==UserScript==
// @name Enlaces Entradas
// @namespace http://use.i.E.your.homepage/
// @version 0.1
// @description enter something useful
// @match http://entradas/*
// @copyright 2012+, You
// ==/UserScript==
$("a[href^=\\/]").not("a[href^=\\/entradas]").css({"padding":"2.5px", "outline": "1px dashed #000", "border": "2.5px solid #DD0"})
@weapp
weapp / nginx.conf
Created August 4, 2014 17:21
Return common errors as json in Nginx
error_page 500 /500.html;
location /500.html{
return 500 '{"error": {"status_code": 500,"status": "Internal Server Error"}}';
}
error_page 502 /502.html;
location /502.html{
return 502 '{"error": {"status_code": 502,"status": "Bad Gateway"}}';
}
@weapp
weapp / _Regions_.md
Last active February 7, 2022 17:21
Experiment about functional programing in different languages

Definitions:

  • callable: something that can be called with params; like a function, method, procedure, macro...
  • Point:: 2d tuple/list/array or object/struct with coordinates (x, y) as attributes/fields
  • Region: a callable that receive a point and return true if is inside of a a region, and false if is out.
  • Distance : a float

Problem:

  • We have a two tanks (in a two positions), and we want to know if we can shot to another positions without danger.
  • The tanks have a secure region defined by a circle
  • The tanks have a maximun shot distance.