Skip to content

Instantly share code, notes, and snippets.

View perenecabuto's full-sized avatar

Felipe Ramos Ferreira (Cabuto) perenecabuto

View GitHub Profile
@lrvick
lrvick / flask_geventwebsocket_example.py
Created September 1, 2011 07:17
Simple Websocket echo client/server with Flask and gevent / gevent-websocket
from geventwebsocket.handler import WebSocketHandler
from gevent.pywsgi import WSGIServer
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@bgentry
bgentry / lock.go
Last active December 13, 2022 08:51
Redis locking in Go with redigo #golang
package main
import (
"github.com/garyburd/redigo/redis"
)
var ErrLockMismatch = errors.New("key is locked with a different secret")
const lockScript = `
local v = redis.call("GET", KEYS[1])
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <linux/i2c-dev.h>
#include <fcntl.h>
#include <sys/ioctl.h>
static void
@alanchrt
alanchrt / triangulate.js
Created January 22, 2014 20:08
Triangulation of three points and radii
var distancePoints = function(p1, p2) {
// Find the distance between two points
return Math.sqrt(Math.pow(p2[0] - p1[0], 2) + Math.pow(p2[1] - p1[1], 2));
};
var intersectCircles = function (c1, r1, c2, r2) {
// Find the points of intersection for two circles
// Based on: http://stackoverflow.com/a/3349134
var d = distancePoints(c1, c2);
if (d > r1 + r2) // Circles do not overlap
@OnlyInAmerica
OnlyInAmerica / make-mega-adblock-hostsfile.sh
Last active September 24, 2024 14:40
Create Mega Adblock Hostsfile for use with Dnsmasq (Modified from Pi-hole)
#!/bin/bash
# Modified Pi-hole script to generate a generic hosts file
# for use with dnsmasq's addn-hosts configuration
# original : https://github.com/jacobsalmela/pi-hole/blob/master/gravity-adv.sh
# The Pi-hole now blocks over 120,000 ad domains
# Address to send ads to (the RPi)
piholeIP="192.168.1.1"
outlist='./final_blocklist.txt'
@perenecabuto
perenecabuto / vpnc-connect.sh
Created June 26, 2015 04:04
vpnc-connect.sh
#!/usr/bin/env bash
lastdata="$HOME/.$(basename $0).db"
lastgateway="$(sed '1q;d' $lastdata)"
lastgroup="$(sed '2q;d' $lastdata)"
lastsecret="$(sed '3q;d' $lastdata)"
lastusername="$(sed '4q;d' $lastdata)"
echo -ne "gateway ($lastgateway): "
read gateway