Skip to content

Instantly share code, notes, and snippets.

View dmiro's full-sized avatar

David Miró dmiro

View GitHub Profile
@dmiro
dmiro / Dockerfile.spinnet
Last active December 5, 2023 16:19
Docker: Install node 12 with nvm (Node Version Manager)
# updating NODE
# to install node 12 we need install with nvm because the new
# installation method (see https://deb.nodesource.com) is only
# supported from version 18
ENV NVM_VERSION v0.39.6
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION v12.22.12
RUN mkdir $NVM_DIR
@dmiro
dmiro / Dockerfile
Last active December 3, 2023 12:27
Docker Multi State Build
## https://docs.docker.com/build/building/multi-stage/
## With multi-stage builds, you use multiple FROM statements in your Dockerfile.
## Each FROM instruction can use a different base, and each of them begins a new stage of the build.
## You can selectively copy artifacts from one stage to another, leaving behind everything you don't
## want in the final image.
# syntax=docker/dockerfile:1
FROM golang:1.21 as build
WORKDIR /src
COPY <<EOF /src/main.go
@dmiro
dmiro / main.cpp
Created November 28, 2023 16:10
I2C scanner
/*********
Rui Santos
Complete project details at https://randomnerdtutorials.com
*********/
#include "Arduino.h"
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600);
@dmiro
dmiro / load_script.js
Last active September 27, 2023 11:21
load script
function loadScript (url, callback) {
// Adding the script tag to the head as suggested before
var head = document.head;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
// Then bind the event to the callback function.
// There are several events for cross browser compatibility.
script.onreadystatechange = callback;
@dmiro
dmiro / anotations.py
Last active September 28, 2022 13:21
add extra info to vars (python >= 3.9)
from typing import Annotated
class Pepe(object):
hola_quillo: Annotated[int, "hola quillo"]
yepale: Annotated[float, "yepa.le"]
todobien: float
def get_display_name(className, varName):
from typing import get_type_hints
hints = get_type_hints(className, include_extras=True)
<html>
<body>
hi
</body>
</html>
@dmiro
dmiro / singleton.py
Created March 9, 2018 08:11
singleton class
class Singleton(object):
_instance = None
def __new__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = object.__new__(cls, *args, **kwargs)
return cls._instance
@dmiro
dmiro / createdbradio.py
Last active August 25, 2023 11:43
Create sqlite database from repository radio-browser.info
import subprocess
import gzip
import os
"""
create sqlite database from repository radio-browser.info
prerequisites:
(1) install sqlite3 (client)
@dmiro
dmiro / SciTEStartup.lua
Last active June 8, 2016 12:42
SciTE properties for Python
function stripTrailingSpaces(reportNoMatch)
local count = 0
local fs,fe = editor:findtext("[ \\t]+$", SCFIND_REGEXP)
if fe then
repeat
count = count + 1
editor:remove(fs,fe)
fs,fe = editor:findtext("[ \\t]+$", SCFIND_REGEXP, fs)
until not fe
print("Removed trailing spaces from " .. count .. " line(s).")
@dmiro
dmiro / anonymous_class.py
Last active May 4, 2016 09:26
anonymous class
#https://docs.python.org/3/library/types.html#types.SimpleNamespace
class SimpleNamespace:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def __repr__(self):
keys = sorted(self.__dict__)
items = ("{}={!r}".format(k, self.__dict__[k]) for k in keys)
return "{}({})".format(type(self).__name__, ", ".join(items))
def __eq__(self, other):