Skip to content

Instantly share code, notes, and snippets.

@ralsina
ralsina / README.md
Last active May 4, 2023 17:21
Dynamically change your VS Code theme using flavours and base16
import cadquery2 as cq
from cadquery2 import exporters
thickness = 12
width = 60
depth = 10
holes = 6
screws = 2
cable_radius = 1.6
length=135
front_h = 10
back_h =20
width = 210
fillet_s = 5
screen_h = 100
kbd_w = 200
kbd_h = 4
kbd_l = 125
@ralsina
ralsina / slides.tmpl
Last active May 18, 2022 07:41
A gallery slideshow shortcode for Nikola
## Nikola slides shortcode
## Put it in shortcodes/ in your site
## Use it like this:
## {{% slides "foo" %}}
## That will create a carousel with all the images from galleries/foo
## This uses bootstrap4 so only works in themes that use it
## Twek as needed for visuals
<%!
import os
@ralsina
ralsina / love-jsonschema.md
Last active July 12, 2020 04:05
How I learned to stop worrying and love JSON Schema
#!/bin/bash -x
DEBUG=4
PUNTODEMONTAJE=/vos/sabras
rdiff-backup -v$DEBUG --print-statistics --exclude ~/.cargo --exclude ~/.local/share/Steam/ --exclude ~/.cache ~ /$PUNTODEMONTAJE/backup-$USER/
rdiff-backup -v$DEBUG --print-statistics --remove-older-than 4W /$PUNTODEMONTAJE/backup-$USER/
rdiff-backup -l /$PUNTODEMONTAJE/backup-$USER/
import subprocess
data = subprocess.check_output('xrandr').decode('utf8').splitlines()
outputs = [x for x in data if x and x[0] not in 'S \t']
def parse_output(line):
parts = line.split()
name = parts[0]
primary = 'primary' in parts
w_in_mm, h_in_mm = [p.split('mm')[0] for p in parts if p.endswith('mm')]
res_x, res_y = [p for p in parts if 'x' in p][0].split('+')[0].split('x')
@ralsina
ralsina / pyparsing tutorial draft.md
Last active September 5, 2018 11:23
Creating DSLs for Dummies

Intro

I don't have the usual programmer's education. I studied maths, and then dropped out of that, and am mostly self-taught. So, there are some parts of programming I always saw wearily, thinking to myself that I really should go to school to learn them. One remarkable such area is parsing and implementing languages.

Well... sure, school is always a good idea, but this is not that hard. In this article I will explain how to go from nothing to a functioning, extensible language, using Python and PyParsing. If you are as scared of grammars, parsers and all that jazz as I used to be, come along, it's pretty simple,

Grammar (part I)

What is a grammar? It's what defines what is and what is not valid in our language, and it's the hardest part to get right, mostly because it's all about making decisions.

The Pleasures of a Cheap Phone

When it comes to phones I am a cheap guy. I don't buy expensive phones, I don't buy flagship phones, I don't even buy "cheap flagship-like phones". I don't buy unknown chinese brands that make amazingly cheap but awesome phones, I don't buy mid-range phones, I don't buy mistery phones. I buy cheap phones. Or at least that is the plan from now on.

My previous phone was a former flagship, a LG G4

@ralsina
ralsina / layout.py
Created March 23, 2018 18:03
Exploratory work
import svgwrite
class Box():
def __init__(self, x=0, y=0, w=1, h=1, red=False, blue=False, yellow=False, letter=None):
self.x = x
self.y = y
self.w = w
self.h = h
self.red = red
self.blue = blue