Skip to content

Instantly share code, notes, and snippets.

View jflopezfernandez's full-sized avatar
🏈
Merry Start of the Football Season Eve!!!

Jose Fernando Lopez Fernandez jflopezfernandez

🏈
Merry Start of the Football Season Eve!!!
View GitHub Profile
@jflopezfernandez
jflopezfernandez / makefile
Last active July 24, 2017 08:40
Fortran Makefile [Debug]
FC := ifort
CFLAGS :=
LFLAGS :=
SRCS := $(wildcard *.f90)
OBJS := $(patsubst %.f90,%.o,$(SRCS))
PROGRAM := dipgen
@jflopezfernandez
jflopezfernandez / modrm_calc.c
Created December 29, 2017 11:55
Verifying Intel MODRM, thanks to Per Vognsen
Intel IA64 Documentation Section 2.1.5: Addressing-Mode Encoding of ModR/M and SIB Bytes
Figure 2-2:
Mod 11
RM 000
/digit (Opcode): REG = 001
--------------------------------
C8H 11001000
@jflopezfernandez
jflopezfernandez / regex-phone-numbers.cpp
Last active May 7, 2018 10:59
Using C++ Standard Library regular expressions to find phone numbers in most common formats
#include <iostream>
#include <regex>
#include <string>
#include <vector>
int main(int argc, char *argv[])
{
const std::string defaultRegex { "\\(?\\d{3}[-\\) ]+\\d{3}[- ]?\\d{4}" };
@jflopezfernandez
jflopezfernandez / regex-iterator.cpp
Last active May 7, 2018 11:12
Matching Subexpressions (XML)
/** In this example, the regular expression /<(.*)>(.*)</(\1)>/ searches for
* any number of any characters in angle brackets, any number of any characters
* in after the angle brackets, and then finally a forward slash followed by
* any number of any characters, again in angle brackets. This thus forms the
* XML tags search expression.
*
*/
#include <iostream>
/** Dietmar Kuhl, the C++ IO and Internationalization expert, wrote this blogpost
* (https://kuhllib.com/2012/01/14/stop-excessive-use-of-stdendl/)
* discussing the need to stop overusing `std::endl`. In the blog post, he implemented
* this function as a replacement.
*
* While it looks almost exactly the same in use, this function only outputs a
* new line character; it does not flush the output stream. In contrast, `std::endl`
* both outputs a new character and calls `std::fflush()`.
*
// MSVC 17 warns about using the `strtok` function
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
template <typename T, typename Traits = char_traits<T>>
std::basic_ostream<T, Traits>&
@jflopezfernandez
jflopezfernandez / read-file-by-chars.cpp
Last active May 7, 2018 13:26
Read text file character by character in C++
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
/** Description:
* Replacement for std::endl. Prints new line without
* flushing the output buffer.
*
@jflopezfernandez
jflopezfernandez / implementing-output-operator.cpp
Last active November 5, 2018 20:25
Defining an output operator for a user-defined type
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
namespace IO
{
template <typename CharT, typename Traits = std::char_traits<CharT>>
@jflopezfernandez
jflopezfernandez / stream-buffer-iterator.cpp
Created May 7, 2018 14:29
Printing the contents of a stream buffer using an iterator
#include <iostream>
#include <iterator>
#include <string>
int main()
{
const std::string text("Hello, my name is Jean-Pierre Williams.");
" =============================================================================
"
"
" VIM CONFIGURATION FILE
"
"
" =============================================================================
set nocompatible