Skip to content

Instantly share code, notes, and snippets.

View mrbitsdcf's full-sized avatar

MrBiTs mrbitsdcf

View GitHub Profile
@mrbitsdcf
mrbitsdcf / ruby_pgp
Created October 22, 2013 12:28
Using PGP assyncronous keys to encrypt data in Ruby
#!/usr/bin/env ruby
require 'openssl'
require 'base64'
public_key_file = '/path/to/key.pem';
string = 'Hello World!';
public_key = OpenSSL::PKey::RSA.new(File.read(public_key_file))
encrypted_string = Base64.encode64(public_key.public_encrypt(string))
@mrbitsdcf
mrbitsdcf / mongodb_autoinc.java
Last active August 29, 2015 14:01
Auto-increment function for MongoDB console
function counter(name) {
return db.counters.findAndModify(
{query:{_id:name},
update:{$inc : {next:1}},
new:true,
upsert:true}
).next;
}
@mrbitsdcf
mrbitsdcf / keybase.md
Last active February 10, 2021 17:44
Keybase Auth

Keybase proof

I hereby claim:

  • I am mrbitsdcf on github.
  • I am mrbits (https://keybase.io/mrbits) on keybase.
  • I have a public key ASClI9nLRabD3Vmd99qw_iXzNglgtv1jYsuV_U06_TVnSgo

To claim this, I am signing this object:

@mrbitsdcf
mrbitsdcf / ssh_paramiko_embeeded_private_key.py
Created November 4, 2014 14:55
SSH with embeeded private key
import paramiko
import StringIO
rsakey_string = 'Put your RSA Private Key string here'
''' alternative method:
rsakey_string = open('/path/to/rsa_private_key_file').read()
'''
keyfile = StringIO.StringIO(rsakey_string)
mykey = paramiko.RSAKey.from_private_key(keyfile)
@mrbitsdcf
mrbitsdcf / gera_cpf.py
Last active August 29, 2015 14:08
Gerador de CPF
import random
def gera_cpf_valido(mask=False):
n = [random.randrange(10) for i in xrange(9)]
# calcula digito 1 e acrescenta ao numero
s = sum(x * y for x, y in zip(n, range(10, 1, -1)))
d1 = 11 - s % 11
@mrbitsdcf
mrbitsdcf / one_way_cypher.py
Created February 20, 2015 10:59
One way cypher
# -*- coding: utf-8 -*-
#!/usr/bin/env python
#
# implements simple one-way encryption pipe using rsa and keccak-based
# spongewrap
#
# useful at least in the following use-case: you have an untrusted
# host on which plaintext data arrives, which you want to encrypt
# before it is forwarded in a hostile environment to the final
# recipient holding a private key in a safe location. In this one-way
#!/usr/bin/env python
import os
u = open('users.txt', 'r')
for user in u.readlines():
user = user[:-1]
path = '/data/users/{0}/'.format(user)
tmp = os.path.isdir(path)
FROM node:boron-alpine
RUN mkdir -p /app
WORKDIR /app
COPY package.json /app/
RUN npm install
COPY . /app
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Distances on Globe and Flat Earth
# Instructions:
# - Input each information as asked;
# - Input coordinates in degrees (23.1234);
# - If coordinates are at South or West, use negative numbers (-23.1234);
# - North Pole to Equator based on a Flat Earth with 40.075km equatorial perimeter.
# Earth radius = 6371km rounded, so little diferences are expected if you're considering WGS84 geoid.
# CONSTANTES
G = 6.67408 * 10**(-11) # Constante Universal de Gravitação
M = 5.972 * 10**(24) # Massa da Terra
# ----------------------------------------------------------------------------------------------------------------------------
# VARIÁVEIS