Skip to content

Instantly share code, notes, and snippets.

View jslvtr's full-sized avatar

Jose Salvatierra jslvtr

View GitHub Profile
@jslvtr
jslvtr / regex.cpp
Last active December 28, 2015 21:19
This is a way to get 3 words of a line that are space separated, sometimes with multiple spaces, written in C++.
std::string text = "Hello sweet world"
// Create cmatch object to match `match_results` objects into string literals
std::cmatch matchStore;
// Create a regex object to contain the strings that are going to be matched against
std::regex reg("([A-z]+)[\\s]+([A-z]+)[\\s]+([A-z]+)");
// `regex_search` will go through the string and store any matchings into `cm`
std::regex_search(text.c_str(), matchStore, reg);
@jslvtr
jslvtr / regex.cpp
Last active December 28, 2015 21:19
This is a way to get three parts out of a line, showing the output, written in C++.
std::string text = "Hello sweet world"
// Create cmatch object to match `match_results` objects into string literals
std::cmatch matchStore;
// Create a regex object to contain the strings that are going to be matched against
std::regex reg("([A-z]+)[\\s]+([A-z]+)[\\s]+([A-z]+)");
// `regex_search` will go through the string and store any matchings into `cm`
std::regex_search(text.c_str(), matchStore, reg);
for(int i = 1; i < matchStore.size(); i++) {
std::cout << "[" << matchStore[i] << "]" << std::endl;
@jslvtr
jslvtr / multtwo.asm
Created November 25, 2013 20:22
This SSEM Assembly program multiplies 750 by 2, getting the result 1500.
; THIS PROGRAM MULTIPLIES A NUMBER BY 2
; Made by Jose Salvatierra
; University of Dundee
VAR 0 ; Fill space
START: LDN NUM1 ; Copy variable negated
SUB NUM1 ; Subtract itself (multiply by 2)
STO MYSUM ; Store it in accumulator
LDN MYSUM ; Negate the answer (make it positive)
STO MYSUM ; Store to variable
STP ; Stop the processor
@jslvtr
jslvtr / blankcode_theme.css
Last active December 30, 2015 17:19
Simple white theme with easy-to-read code for Marked, the Markdown reader (www.markedapp.com). Made by Jose Salvatierra (http://jslvtr.com)
/*
This document has been created with Marked.app <http://markedapp.com>, Copyright 2011 Brett Terpstra
Please leave this notice in place, along with any additional credits below.
---------------------------------------------------------------
Title: Blank/Code Theme
Author: Jose Salvatierra &c 2013-4 jslvtr.com
Description: A very simple theme with Garamond as a main font. Titles are in Crimson Text, and the code in Source Code Pro or Consolas.
*/
body
@jslvtr
jslvtr / mult_two.asm
Created December 23, 2013 12:26
This is a thoroughly-commented piece of ASSEMBLY code.
; THIS PROGRAM MULTIPLIES A NUMBER BY 2
; Made by Jose Salvatierra
; For a further explanation go to
START: LDN NUM1 ; Copy variable negated into the accumulator (this is the value we are working with in the processor)
SUB NUM1 ; Subtract from the value in the accumulator the value of NUM1 (this is essentially multiplying by 2)
STO MYSUM ; Store to variable (copy the value we're working with to the variable MYSUM)
LDN MYSUM ; Get the value of the variable multiplied by -1 (negated) into the accumulator
STO MYSUM ; Store to variable (copy the value we're working with to the variable MYSUM)
STP ; Stop the processor (ends the program)
NUM1: VAR 750 ; Declare 32-bit variable with value 750
@jslvtr
jslvtr / srt_typing.py
Created January 14, 2016 00:10
A small program to convert newline-separated lines into .SRT-compliant files
import datetime
import os
import sys
__author__ = 'Jose Salvatierra'
path = os.path.dirname(os.path.realpath(__file__))
def write_section(content, current_id, last_end_time):
@jslvtr
jslvtr / user_authentication.py
Last active April 17, 2022 03:01
Simple authentication with encryption using Flask and Python
"""
This file defines a User model and a Flask application, and implements authentication using encryption.
For more information, visit http://tecladocode.com/blog/learn-python-password-encryption-with-flask
"""
from flask import Flask, request, jsonify
from werkzeug.security import generate_password_hash, check_password_hash
import sqlite3
@jslvtr
jslvtr / send_email.py
Created April 7, 2018 14:27
Sending e-mails with Python
import smtplib
from email.message import EmailMessage
email = EmailMessage()
email['Subject'] = 'Test email'
email['From'] = '[email protected]'
email['To'] = '[email protected]'
@jslvtr
jslvtr / test_list_reversal.py
Last active May 30, 2019 07:58
Introduction to unit testing with Python (https://blog.tecladocode.com/introduction-to-unit-testing-with-python/) — final complete code
from unittest import TestCase
from typing import List
def has_mixed_types(list_: List):
first = type(list_[0])
return any(not isinstance(t, first) for t in list_)
def reverse_list(original: List) -> List:
if has_mixed_types(original):
raise ValueError("The list to be reversed should have homogeneous types.")
@jslvtr
jslvtr / form.html
Created August 21, 2020 15:59
The HTML and CSS Code for our Flask Tutorial for Beginners video (https://youtu.be/lIGKKnfLobA)
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Personal finance</title>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<h1>Add transaction</h1>
<form>