Skip to content

Instantly share code, notes, and snippets.

View jazlopez's full-sized avatar
🏠

Jaziel Lopez jazlopez

🏠
  • Thermo Fisher Scientific
  • Tijuana, MX
View GitHub Profile
@jazlopez
jazlopez / valid.signatures.in.c.md
Created December 31, 2023 21:02
Valid main signatures in C

main() should be declared as either:

int main(void)
int main(int argc, char **argv)

Or equivalent. For example

@jazlopez
jazlopez / exit.status.code.in.c.program.md
Last active December 31, 2023 21:11
exit.status.code.in.c.program.md

EXIT_FAILURE, either in a return statement in main or as an argument to exit(), is the only portable way to indicate failure in a C or C++ program. exit(1) can actually signal successful termination on VMS, for example.

If you're going to be using EXIT_FAILURE when your program fails, then you might as well use EXIT_SUCCESS when it succeeds, just for the sake of symmetry.

On the other hand, if the program never signals failure, you can use either 0 or EXIT_SUCCESS. Both are guaranteed by the standard to signal successful completion. (It's barely possible that EXIT_SUCCESS could have a value other than 0,

@jazlopez
jazlopez / security.conf
Created October 27, 2023 16:56 — forked from ambroisemaupate/security.conf
Nginx CSP example
# config to don't allow the browser to render the page inside an frame or iframe
# and avoid clickjacking http://en.wikipedia.org/wiki/Clickjacking
# if you need to allow [i]frames, you can use SAMEORIGIN or even set an uri with ALLOW-FROM uri
# https://developer.mozilla.org/en-US/docs/HTTP/X-Frame-Options
add_header X-Frame-Options SAMEORIGIN;
# when serving user-supplied content, include a X-Content-Type-Options: nosniff header along with the Content-Type: header,
# to disable content-type sniffing on some browsers.
# https://www.owasp.org/index.php/List_of_useful_HTTP_headers
# currently suppoorted in IE > 8 http://blogs.msdn.com/b/ie/archive/2008/09/02/ie8-security-part-vi-beta-2-update.aspx
@jazlopez
jazlopez / py-ml-cost-fn-linear-regression.py
Created October 16, 2023 03:56
Python/ML Exercise Computes Cost Function Linear Regresion
import numpy as np
import matplotlib.pyplot as plt
def compute_cost(x, y, w, b):
"""
Computes the cost function for linear regression.
Args:
x (ndarray): Shape (m,) Input to the model (Population of cities)
y (ndarray): Shape (m,) Label (Actual profits for the cities)
@jazlopez
jazlopez / create.issue.jira.py
Created October 5, 2023 20:48
Crate JIRA Issue Python
import os
from jira import JIRA
auth = {
'url': 'https://jira.amer.thermo.com/',
'user': os.getenv('JIRA_USER', ''),
'password': os.getenv('JIRA_PASSWORD', '')
}
@jazlopez
jazlopez / fix.cerbot.installation.sh
Created September 9, 2023 20:09
Fix cerbot utility script to renew certificates
# certbot utility stopped working failing with this error
# No module named '_cffi_backend'
# resolution
sudo apt install python3-dev build-essential libssl-dev libffi-dev python3-setuptools
python3 -m pip install cffi
# retry it should work
certbot
@jazlopez
jazlopez / non.instatiable.class.enforcement.md
Created July 2, 2023 22:40
From effective Java 3rd Edition

Enforce noninstantiability with a private constructor

To write a class that is just a grouping of static methods and static fields whose design does not require a constructor to be instantiated.

// Noninstantiable utility class
public class UtilityClass {
  // Suppress default constructor for noninstantiability
 private UtilityClass() {
@jazlopez
jazlopez / builder.pattern.md
Created July 2, 2023 22:34
From effective Java 3rd. Edition

Builder Pattern

With this pattern instead of calling the class constructur instead use a static factory method with all of the required parameters and gets a builder object. Then calls setter-like methods on the builder object to set each optional parameter of interest. Finally, calls a parameterless buildmethod to generate the object, which is typically immutable.

public class NutritionFacts { 
  private final int servingSize; 
  private final int servings; 
  private final int calories; 
  private final int fat;
@jazlopez
jazlopez / factory.method.instead.of.constructors.md
Last active July 2, 2023 22:34
From effective Java 3rd Edition

Static factory methods instead of constructors

Source: Effective Java 3rd. Edition

Common names for static factory methods

from—type

A conversion method that takes a single parameter and returns a corresponding instance of this type, for example:

@jazlopez
jazlopez / demo.triggers.mysql.archived.sql
Created May 3, 2023 00:09
Demo Triggers Database [Archived]
DROP TRIGGER IF EXISTS db_enrollments.on_insert_transaction_creates_event;
DROP TRIGGER IF EXISTS db_enrollments.on_udate_transaction_record_event_transitions;
DROP TABLE IF EXISTS events;
DROP TABLE IF EXISTS transacts;
CREATE TABLE transacts (
transact_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
transact_status ENUM("CREATED", "IN_MEM", "RELEASE_MEM", "PROC_STALL", "OK", "FAILED") DEFAULT "CREATED",
transact_data TEXT NULL,
transact_deleted TINYINT NOT NULL DEFAULT 0, -- soft delete (retain transact status information to easy rollback)