Skip to content

Instantly share code, notes, and snippets.

View wagnerluis1982's full-sized avatar

Wagner Macedo wagnerluis1982

View GitHub Profile
@wagnerluis1982
wagnerluis1982 / cryptutil.py
Created May 26, 2018 18:08
Crypt functions in Python that mimic Java's PBEWithMD5AndDES algorithm to produce a DES key
"""Mimic Java's PBEWithMD5AndDES algorithm to produce a DES key
Closely based in https://stackoverflow.com/a/44509919
"""
import base64
import re
from Crypto.Cipher import DES
from Crypto.Hash import MD5
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet("/welcome")
public class ExemploServlet extends HttpServlet {
@wagnerluis1982
wagnerluis1982 / web.xml
Created August 26, 2017 13:00
Configuração de Aplicação Web Java
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>watermelon</servlet-name>
<servlet-class>myservlets.watermelon</servlet-class>
</servlet>
@wagnerluis1982
wagnerluis1982 / Database.java
Last active June 12, 2017 20:56
Arquivos de apoio da aula de "Criando Serviços REST usando Java EE"
package fanese.web.model;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class Database {
private static final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
@wagnerluis1982
wagnerluis1982 / hastag_tools.py
Last active July 14, 2016 20:44
Function to find hashtags in a string
#!/usr/bin/env python3.4
def hashtags(text):
return set(re.findall(r"(?:^|\W+)#+(\w+(?!#+.*))\b", text))
public interface InterceptHandler {
InterceptEnum beforePublish(ProtocolEvent evt, InterceptContinue continuation);
InterceptEnum beforeSubscribe(ProtocolEvent evt, InterceptContinue continuation);
InterceptEnum beforeConnect(ProtocolEvent evt, InterceptContinue continuation);
void onConnect(ConnectMessage msg);
void onPublish(PublishMessage msg);
void onSubscribe(SubscribeMessage msg);
void onUnsubscribe(SubscribeMessage msg);
}
public class MyInterceptor extends AbstractInterceptor {
private static PrintStream log;
static {
try {
final File f = new File("/tmp/moquette-subscribe-events.log");
log = new PrintStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
@wagnerluis1982
wagnerluis1982 / contador.py
Created May 27, 2012 17:36
Source code lines and statements counter (Contador de linhas e estruturas de código fonte)
import sys, os, re
info = {"folder": sys.argv[1], "extensions": sys.argv[2].split(","), "statements": dict.fromkeys(["if", "for", "while", "do", "switch", "case"], 0), "lines": 0}
for dirpath, dirnames, filenames in os.walk(info["folder"]):
for filelines in [open(os.path.join(dirpath, fname)).readlines() for fname in filenames if fname.split(".")[-1] in info["extensions"]]:
for line in filelines:
info["lines"] += 1
found = re.search(r"^\s*(%s)\b" % "|".join(info["statements"].keys()), line)
if found != None: info["statements"][found.group(1)] += 1
print "O seu codigo possui:\n %d linhas\n" % info["lines"] + "\n".join(" %s: %d" % (k, v) for k, v in info["statements"].iteritems())
@wagnerluis1982
wagnerluis1982 / hello.asm
Created May 24, 2012 00:30
Hello World em Assembly no Linux
section .data
msg db 'Hello World', 0xa ; variável db
len equ $ - msg ; tamanho variável
global _start
_start:
mov edx, len
mov ecx, msg
mov ebx, 1 ; File Descriptor (stdout)
@wagnerluis1982
wagnerluis1982 / word_wrap.py
Created February 25, 2011 17:11
Formatador de texto com coluna fixa
import unittest
def word_wrapper(frase, coluna):
linha = 0
palavras = []
frases = []
for palavra in frase.split():
tamanho_palavra = len(palavra) + 1