Skip to content

Instantly share code, notes, and snippets.

@porfirion
porfirion / check.sh
Created March 28, 2024 12:38
Check Go version
# authored by @barbashov
go_version=$(go version | grep -o '1\.[0-9]*')
if (( $(echo "$go_version >= 1.18" | bc -l) )); then
echo 'newer'
else
echo 'older'
fi
@porfirion
porfirion / main.go
Last active January 19, 2023 01:07
Conditions with parametric types
package main
import (
"errors"
"fmt"
"math/rand"
"strconv"
"time"
"unsafe"
)
#!/usr/bin/env bash
if [ $# -eq 0 ]
then
echo "Usage: $0 DIRECTORY"
echo " DIRECTORY is a go project directory to build"
exit 1
fi
@porfirion
porfirion / NumberInput.js
Created October 13, 2020 16:39
Vue.js 3 minimalistic number input
export default {
props: {
modelValue: [Number, String],
min: {
type: [Number, String],
default: null,
},
max: {
type: [Number, String],
default: null,
// holds list of already existing entities ('a list)
// Allows to check if new entities already exist in list.
// if entity already exists - add it's id into idsList
// if entity doesn't exists - add to existing, add to list of notExistedEntities, add it's id into idsList
type EntityHolder(initialEntities: 'a seq, idGetter: 'a -> string, entityComparator: 'a -> 'a -> bool) =
let mutable existingEntities : 'a list = initialEntities |> Seq.toList
member this.Add (entities: 'a seq) : 'a list * string list =
@porfirion
porfirion / git_version_json.sh
Created March 28, 2019 13:39
Example of generation version.json file from git commit info to use in Jenkins
git log -1 --pretty=format:' {"id": "%H", "id_short": "%h", "message": "%s", "author": "%aN", "date": "%aD", "comitter": "%cN", "commit_date": "%cD", ' \
| (cat && printf '"build_date": "%s",' "$(date -R)") \
| (cat && printf '"branch": "%s"' "${BRANCH}") \
| (cat && printf '}') > version.json
var str: "value" = "test" // error
var str2: "value" = "test" as "value" // ok
var str3: string = "my string" // assignment of healthy man
var str4: string = {} // error
var str5: string = {} as string // OK
var str6: string = {} as "anything" // OK!!
type Duumvirate = 1 | 2
var int: Duumvirate = 3 as 1 // OK!!!
@porfirion
porfirion / index.html
Created March 5, 2019 17:30
Empty favicon (valid PNG)
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
┌─────┬──────┐
│ │ │
├─────┼──────┤
│ │ │
└─────┴──────┘
╔═════╦══════╗
║ ║ ║
╠═════╬══════╣
║ ║ ║