Skip to content

Instantly share code, notes, and snippets.

@jameshanlon
jameshanlon / smtp_tls_test.py
Created February 23, 2022 10:57
SMTP TLS test
import smtplib
from email.mime.text import MIMEText
username =
password =
server =
port = 587
receiver =
sender =
@jameshanlon
jameshanlon / wildcard_matching.cpp
Created December 22, 2020 09:34
Wildcard pattern matching
#include <iostream>
#include <string>
bool matchWildcard(const std::string &text, const std::string &pattern) {
auto itt = text.begin();
for (auto itp = pattern.begin(); itp != pattern.end(); ) {
// Skip multiple * characters.
if (*itp == '*' && *std::next(itp) == '*') {
itp++;
continue;
@jameshanlon
jameshanlon / boost_python_list_vector.cpp
Last active March 15, 2020 20:10 — forked from marcinwol/example.cpp
Boost python vector to py list and py list to vector
#include <iostream>
#include <vector>
#include <memory>
#include "boost/shared_ptr.hpp"
#include "boost/python.hpp"
#include "boost/python/stl_iterator.hpp"
using namespace std;
@jameshanlon
jameshanlon / test_swap.c
Created August 24, 2018 14:51
Test swapping bytes
#include <assert.h>
#include <stdio.h>
#include <stdint.h>
#include <limits.h>
static inline uint32_t swap1(uint32_t x) {
return ((x >> UINT32_C(16)) & 0xFFFF) | ((x & 0xFFFF) << UINT32_C(16));
}
static inline uint32_t swap2(uint32_t x) {
module fsm
(
input logic i_clk,
input logic i_rst,
input logic i_start,
input logic i_finish,
input logic i_wait,
output logic [1:0] o_state,
);
module mux2
#(parameter p_width = 8)
(
input logic [p_width-1:0] i_op_a,
input logic [p_width-1:0] i_op_b,
input i_sel,
output logic [p_width-1:0] o_res
);
always_comb begin
@jameshanlon
jameshanlon / log_server.py
Created February 15, 2018 09:07
Simple log server
import SimpleHTTPServer
import SocketServer
import sys
PORT = 1548
class MyHTTPHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
log_file = open('logfile.txt', 'w')
def log_message(self, format, *args):
self.log_file.write("%s - - [%s] %s\n" %
@jameshanlon
jameshanlon / memcpy_ptr_alias_test.cpp
Created September 19, 2016 07:50
C++ memcpy vs shifts test
#include <cstring>
#include <vector>
#include <inttypes.h>
#include <ctime>
#include <iostream>
#define REPEATS 100000000
#define LO 2
#define HI 3
\documentclass{article}
\usepackage{mathptmx}
\usepackage{tikz}
\usetikzlibrary{calc,fit,arrows,automata,positioning}
%\usepackage{color}
\usepackage[active,pdftex,tightpage]{preview}
\PreviewEnvironment[]{tikzpicture}
\PreviewEnvironment[]{pgfpicture}
\DeclareSymbolFont{symbolsb}{OMS}{cmsy}{m}{n}
\SetSymbolFont{symbolsb}{bold}{OMS}{cmsy}{b}{n}
@jameshanlon
jameshanlon / walk_dirs.py
Created September 19, 2016 07:48
Python walk directories example
import os
import sys
import mimetypes
for root, directories, filenames in os.walk(sys.argv[1]):
for directory in directories:
print os.path.join(root, directory)
for filename in filenames:
mt = mimetypes.guess_type(filename)
print os.path.join(root,filename) + ", type "+str(mt)