Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
https://bergpb.github.io

Berg Paulo bergpb

💻
https://bergpb.github.io
View GitHub Profile
@bergpb
bergpb / sources.list
Created Jul 18, 2017 — forked from kstroud1/sources.list
sources.list for 13.04
View sources.list
# deb cdrom:[Ubuntu 13.04 _Raring Ringtail_ - Release amd64 (20130424)]/ raring main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://old-releases.ubuntu.com/ubuntu/ raring main restricted
deb-src http://old-releases.ubuntu.com/ubuntu/ raring main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://old-releases.ubuntu.com/ubuntu/ raring-updates main restricted
@bergpb
bergpb / rest-server.py
Created Aug 21, 2017 — forked from miguelgrinberg/rest-server.py
The code from my article on building RESTful web services with Python and the Flask microframework. See the article here: http://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask
View rest-server.py
#!flask/bin/python
from flask import Flask, jsonify, abort, request, make_response, url_for
from flask.ext.httpauth import HTTPBasicAuth
app = Flask(__name__, static_url_path = "")
auth = HTTPBasicAuth()
@auth.get_password
def get_password(username):
if username == 'miguel':
@bergpb
bergpb / huffman.py
Created Oct 24, 2017 — forked from mreid/huffman.py
Example implementation of Huffman coding in Python
View huffman.py
# Example Huffman coding implementation
# Distributions are represented as dictionaries of { 'symbol': probability }
# Codes are dictionaries too: { 'symbol': 'codeword' }
def huffman(p):
'''Return a Huffman code for an ensemble with distribution p.'''
assert(sum(p.values()) == 1.0) # Ensure probabilities sum to 1
# Base case of only two symbols, assign 0 or 1 arbitrarily
if(len(p) == 2):
@bergpb
bergpb / pdf2txt.rb
Created Nov 17, 2017 — forked from emad-elsaid/pdf2txt.rb
PDF to Text converter using ruby
View pdf2txt.rb
#!/usr/bin/env ruby
require 'pdf/reader' # gem install pdf-reader
# credits to :
# https://github.com/yob/pdf-reader/blob/master/examples/text.rb
# usage example:
# ruby pdf2txt.rb /path-to-file/file1.pdf [/path-to-file/file2.pdf..]
ARGV.each do |filename|
PDF::Reader.open(filename) do |reader|
@bergpb
bergpb / gist:0f6f89fb39684d5685e2fa64b2140e89
Created Dec 12, 2017 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup
View gist:0f6f89fb39684d5685e2fa64b2140e89

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@bergpb
bergpb / ngrok_url_api.js
Created Jan 30, 2018
Get ngrok public url in api with node.
View ngrok_url_api.js
//Execute with: node ngrok_url_api.js
const request = require("request");
const url = "http://127.0.0.1:4040/api/tunnels";
request.get(url, function(error, res, body) {
get_url = JSON.parse(body);
console.log(get_url.tunnels[0].public_url);
});
View verifica_tamanho_pasta.py
import os
import sys
#check if sys.argv is set:
if len(sys.argv) > 1:
dir = sys.argv[1]
else:
dir = os.getcwd()
#go to dir
@bergpb
bergpb / convert_doc_to_pdf.py
Last active Apr 11, 2018
Convert '.doc' into a '.pdf' file.
View convert_doc_to_pdf.py
# -*- coding: utf-8 -*-
import os
#install this dependency
#sudo apt-get install unoconv
for file in os.listdir(os.getcwd()):
#remove all spaces in filename
new_file = file.replace(' ', '_')
@bergpb
bergpb / factorial_recursive.py
Last active Apr 16, 2018
Recursive factorial in python.
View factorial_recursive.py
import sys
n = int(sys.argv[1])
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
View PostgreSQL JPA Hibernate persistence.xml
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="persistenceUnitName" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" /> <!-- DB Driver -->