Skip to content

Instantly share code, notes, and snippets.

@jvmvik
jvmvik / shell_tips.md
Created November 21, 2023 13:13
Shell broken on exit code 1

If the parent script runs with fail on error switch: tcsh -e but a sub script issue a exit code non zero. Then the parent will fail like a Jenkins pipeline, Bamboo job or else.

This switch allows easy pipeline debug by stopping the script when exit code > 0

/bin/tcsh -fe
source path/to/bin/sourceme
# display each command executed
set echo
@jvmvik
jvmvik / karabiner.json
Created February 1, 2023 02:51
Mac secondary keyboard to execute shortcut only
// after trying to build my own shortcut keyboard with arduino.
// I realize that it would be time and cost effective to re-use a spare mechanical keyboard to execute my shortcut.
// Karabiner offers a simple easy solution even it's a bit of twist.
//
// source: https://stackoverflow.com/questions/63194740/karabiner-elements-map-a-key-to-a-combination-keys
//
// edit: ~/.config/karabiner/karabiner.json
//
// Remap the secondary keyboard key d to command + d -> duplicate line in the VS code command palette
"devices": [
@jvmvik
jvmvik / Jenkins_ci.md
Created December 22, 2022 14:35
Jenkins gist

Jenkins CI

Check the disk space with a self contain script based on Ruby Execute this shell scritp on remote host using ssh

rm check_disk.rb

tee -a check_disk.rb <<EOF 
# parse mount point VM (TODO customize for your machine)
@jvmvik
jvmvik / apple_si.md
Created November 28, 2022 18:50
Apple silicon commands

Install nokogiri on Apple silicon using default Ruby installation

arch -x86_64 gem install nokogiri -v '1.10.10' --platform=ruby -- --use-system-libraries
@jvmvik
jvmvik / logging_simple.rb
Created August 31, 2022 13:40
Ruby log simple colorful implementation
module Logging
ESCAPES = { :green => "\033[32m",
:yellow => "\033[33m",
:red => "\033[31m",
:reset => "\033[0m" }
def info(message)
emit(:message => message, :color => :green)
end
@jvmvik
jvmvik / Rakefile.rb
Last active November 9, 2022 21:50
Rake Quick Reference
# Rake Quick Reference
#
# Rake is amazing automation tools based on Ruby.
# Rake open source documentation is pretty limited relative to the tool capability.
#
# It's better than Makefile because it's more dynamic.
# while Makefile are pretty flexible, there are a lot of builtin rules
# and conventions that must be follow.
# This make pretty hard to learn, debug and scaling can be frustrating.
#
@jvmvik
jvmvik / demo.py
Created April 3, 2021 13:00
Dynamic Python object creation
# data
data = '''<?xml version="1.0" encoding="UTF-8"?>
<menza>
<date day="Monday">
<meal name="Potato flat cakes">
<ingredient name="potatoes"/>
<ingredient name="flour"/>
<ingredient name="eggs"/>
</meal>
<meal name="Pancakes">
@jvmvik
jvmvik / array.rb
Created April 1, 2021 19:31
Ruby - Monkey patch the basic hash and array for more productivity
# Monkey patch Ruby Array class
#
class Array
def each_with_last
size = self.size
each_with_index do |e, index|
yield(e, (index == size-1))
end
end
@jvmvik
jvmvik / error_404.html
Created October 26, 2020 04:00
error_404.html
<html>
<head>
<title>Oops server is dead!</title>
<style>
html {
background: #262b30;
height: 100%;
}
body {
/*
* Generate gift paper from random images.
*/
package main
import (
"fmt"
"image"
"image/jpeg"