Skip to content

Instantly share code, notes, and snippets.

View mendelgusmao's full-sized avatar
😅
what's up?

Mendelson Gusmão mendelgusmao

😅
what's up?
View GitHub Profile
@juanplopes
juanplopes / gist:1974922
Created March 4, 2012 21:41
Simple RSA impl (revisited)
def gcd(a,b):
if b==0: return (1, 0)
q = a/b
x,y = gcd(b, a-q*b)
return (y, x-q*y)
def inverse(a, b):
x,y = gcd(a,b)
return (x if x > 0 else x+b)
@jaygooby
jaygooby / dropbox
Created June 18, 2012 14:29
/etc/init.d script for dropbox on Ubuntu
#!/bin/sh
#
# Copied from http://forums.dropbox.com/topic.php?id=38529#post-414344
# Modified by jay@gooby.org (@jaygooby on Twitter)
### BEGIN INIT INFO
# Provides: dropbox
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
{
"path":"/home/foo/icons/",
"domain":"example.com",
"icons":[
{"host":"aaa.example.com", "icon":"red.png"},
{"host":"bbb.example.com", "icon":"green.png"},
{"host":"ccc.example.com", "icon":"yellow.png"},
{"host":"ddd.example.com", "icon":"orange.png"},
{"host":"eee.example.com", "icon":"blue.png"},
{"host":"fff.example.com", "icon":"cyan.png"},
@klalle
klalle / EnergyMeter.ino
Last active March 28, 2020 00:13
EnergyMeter
/*
Reads voltage and power from China-style energy meter.
Collecting data by eavesdropping on the MOSI-line (master in slave out)
between the energy monitoring chip (ECH1560) and the main processor*/
const int CLKPin = 2; // Pin connected to CLK (D2 & INT0)
const int MISOPin = 5; // Pin connected to MISO (D5)
//All variables that is changed in the interrupt function must be volatile to make sure changes are saved.
volatile int Ba = 0; //Store MISO-byte 1

Guide to how fucked is SSL?

Thanks to Jacob Kaplan-Moss, Donald Stufft, David Reid, Allen Short, Zain Memon, and Chris Armstrong for review.

This is a guide for technical individuals to understand in what circumstances SSL communications are secure against an observer-in-the-middle (for all intents and purposes: the NSA).

@DavidVaini
DavidVaini / round.go
Created April 9, 2014 19:58
Arggh Golang does not include a round function in the standard math package. So I wrote a quick one.
package main
import (
"log"
"math"
)
func Round(val float64, roundOn float64, places int ) (newVal float64) {
var round float64
pow := math.Pow(10, float64(places))
@henrik
henrik / rules.md
Last active May 23, 2022 12:31
Sandi Metz' four rules from Ruby Rogues episode 87. Listen or read the transcript: http://rubyrogues.com/087-rr-book-clubpractical-object-oriented-design-in-ruby-with-sandi-metz/
  1. Your class can be no longer than 100 lines of code.
  2. Your methods can be no longer than five lines of code.
  3. You can pass no more than four parameters and you can’t just make it one big hash.
  4. When a call comes into your Rails controller, you can only instantiate one object to do whatever it is that needs to be done. And your view can only know about one instance variable.

You can break these rules if you can talk your pair into agreeing with you.

@vitex
vitex / README.md
Created December 7, 2012 15:00
A script to build Haserl 0.9.29 with LuaJIT 2.0

This script modifies the Haserl 0.9.29 distribution so it works with LuaJIT 2.0 as well as Lua 5.1. The script takes a single argument that is the path to a LuaJIT / Lua distribution directory in which library and executable files have been built. A typical usage is

    ./build-haserl-luajit.sh /usr/local/src/LuaJIT-2.0.0/

The script patches configure.ac, builds Haserl, and executes a CGI script to verify that LuaJIT / Lua is working within Haserl.

The LuaJIT distribution builds both .so and .a libraries; this script always uses the .a library so the Haserl executable contains an embedded copy of LuaJIT. If you prefer to link dynamically to LuaJIT, modify the script to change

    [ LIBS="-Wl,-Bstatic -l$LUALIB -Wl,-Bdynamic $LIBS" ]
@kdzwinel
kdzwinel / trilateration.js
Created January 3, 2014 09:35
Simple trilateration algorithm implementation in JavaScript.
function getTrilateration(position1, position2, position3) {
var xa = position1.x;
var ya = position1.y;
var xb = position2.x;
var yb = position2.y;
var xc = position3.x;
var yc = position3.y;
var ra = position1.distance;
var rb = position2.distance;
var rc = position3.distance;
@dergachev
dergachev / squid-deb-proxy_on_docker.md
Last active May 25, 2023 03:55
Caching debian package installation with docker

TLDR: I now add the following snippet to all my Dockerfiles:

# If host is running squid-deb-proxy on port 8000, populate /etc/apt/apt.conf.d/30proxy
# By default, squid-deb-proxy 403s unknown sources, so apt shouldn't proxy ppa.launchpad.net
RUN route -n | awk '/^0.0.0.0/ {print $2}' > /tmp/host_ip.txt
RUN echo "HEAD /" | nc `cat /tmp/host_ip.txt` 8000 | grep squid-deb-proxy \
  && (echo "Acquire::http::Proxy \"http://$(cat /tmp/host_ip.txt):8000\";" > /etc/apt/apt.conf.d/30proxy) \
  && (echo "Acquire::http::Proxy::ppa.launchpad.net DIRECT;" >> /etc/apt/apt.conf.d/30proxy) \
  || echo "No squid-deb-proxy detected on docker host"