Skip to content

Instantly share code, notes, and snippets.

View jorgeacortes's full-sized avatar

Jorge jorgeacortes

View GitHub Profile
@jorgeacortes
jorgeacortes / index.php
Last active August 11, 2018 23:45
Sample PHP post endpoint.
<?php
echo(' <!DOCTYPE html>
<html>
<body>
<h1>Post received!</h1>
');
?>
<?php
//You can output the post content to a file to be read later
file_put_contents('test.txt', file_get_contents('php://input'));
@jorgeacortes
jorgeacortes / pre-push
Created June 24, 2019 08:58
Git pre-push hook to locally reject pushing branches containing 'local/'
#!/bin/sh
# Called by "git push" after it has checked the remote status,
# but before anything has been pushed.
#
# If this script exits with a non-zero status nothing will be pushed.
#
# Steps to install, from the root directory of your repo...
# 1. Copy the file into your repo at `.git/hooks/pre-push`
# 2. Set executable permissions, run `chmod +x .git/hooks/pre-push`
@jorgeacortes
jorgeacortes / github-api-get.py
Last active July 27, 2020 17:53
Example of a get request to Github api using python with autentication
import requests
headers = {'Authorization': 'token xxxxx'}
action = "jorgeacortes/stm32-cmake-docker/traffic/clones"
resp = requests.get('https://api.github.com/repos/'+ action, headers=headers)
print(resp.json())
@jorgeacortes
jorgeacortes / stm32_internal_temperature_sensor.c
Created August 1, 2020 14:39
Converts ADC value of the internal temperature sensor of STM32 microcontroller to degrees Celsius taking into account calibration.
/**
* @brief Converts ADC_CHANNEL_TEMPSENSOR ADC value to Temperature in ºC.
* @param[in] sample ADC_CHANNEL_TEMPSENSOR value read.
* @return temperature in float.
* @note This temperature sensor measures junction temperature of the microcontroller.
* */
float temp_calc(uint16_t sample) {
/* Factory calibrated values. Address for STM32F072x8 and STM32F072xB. Check datasheet for each microcontroller */
const uint16_t ADC_TEMP_3V3_30C = *((uint16_t *)(0x1FFFF7B8));
const float TEMP_30C = 30.0F;
@jorgeacortes
jorgeacortes / register32_t.h
Last active October 17, 2020 18:03
Sample type for 32bit register with bit and value access in C (little endian machine).
union register32_t {
uint32_t val;
struct {
uint32_t b0:1;
uint32_t b1:1;
uint32_t b2:1;
uint32_t b3:1;
uint32_t b4:1;
uint32_t b5:1;
uint32_t b6:1;
@jorgeacortes
jorgeacortes / fetchWpPost.js
Last active August 15, 2020 15:20
Functions to retrieve a Wordpress post data.
/* Retrieves Wordpress post data of the post number idx from a domain.
* Note: idx is the index of the response array of posts.
*/
async function fetchWpPost(domain, idx) {
try {
var ret = {};
const response = await fetch('https://'+domain+'/wp-json/wp/v2/posts')
.then(response => response.json())
.then(data => {
ret.title = data[idx].title.rendered;
@jorgeacortes
jorgeacortes / stampGitHash.cmake
Created August 16, 2020 14:47
Stamp the Git Hash into a project define
# Use GIT_HASH define to get the git hash in your code like this:
# const int8_t kGitHash[] = GIT_HASH;
macro(stampGitHash)
set (git_cmd "git")
set (git_arg "rev-parse")
set (git_arg2 "HEAD")
execute_process(COMMAND ${git_cmd} ${git_arg} ${git_arg2}
RESULT_VARIABLE git_result
OUTPUT_VARIABLE git_hash)
SET(git_hash "\"${git_hash}\"")
@jorgeacortes
jorgeacortes / settings.json
Last active September 28, 2020 13:42
Windows terminal custom settings
// Properly delimiter words similar to bash (https://github.com/microsoft/terminal/issues/3196)
"wordDelimiters" : " ()\"':,;<>~!@#$%^&*|+=[]{}~?│",
"profiles":
{
"defaults":
{
"fontFace": "MesloLGLDZ Nerd Font Mono",
"fontSize": 9,
"fontWeight": "medium"
@jorgeacortes
jorgeacortes / swap32.js
Created October 19, 2020 06:14
Function for swapping endianess of 32 bits unsigned value (unsigned)
/**
* @brief swaps a 32 bits value unsigned
* @param val value to swap
* @return Unsigned swapped value
*/
function swap32(val) {
let swapped =
((val & 0xff) << 24)
| ((val & 0xff00) << 8)
| ((val >> 8) & 0xff00)
@jorgeacortes
jorgeacortes / nodejs_run_docker.sh
Created October 20, 2020 06:06
Docker run example doing a bind mount excluding node_modules folder that is inside the shared folder.
docker run --rm -v $(pwd):/home/node/app -v /home/node/app/node_modules node:latest bash -c "npm start"