Skip to content

Instantly share code, notes, and snippets.

@innermond
innermond / gist:ed34fa2fba258237849bc6d63bb998dc
Created June 23, 2019 07:04
gopdf set custom page and use utf8
var err error
// set default page sra3
sra3 := gofpdf.SizeType{450, 320}
pdf := gofpdf.NewCustom(&gofpdf.InitType{UnitStr: "mm", Size: sra3})
pdf.SetCompression(false)
// Margins of page
pdf.SetMargins(0.0, 0.0, 0.0)
pdf.SetAutoPageBreak(false, 0.0)
@innermond
innermond / gist:706ddf1440bd3606214da56860d1d058
Created December 8, 2018 09:55
use sed to add srcset tag to a img tag that misses it
sed -i -e 's/<img src="\[HOST\]\/img\/\([^"]*\)"/<img src="[HOST]\/img\/\1" srcset="[HOST]\/img\/\1 700w,[HOST]\/img\/400w\/\1 400w" sizes="(max-width: 480px) 100vw, 70vw"/g' <html-file>
@innermond
innermond / gist:02e0bc1b041ec7e6a2ad649a9e875c60
Created December 5, 2018 14:50
example how to cancel, timeout, ctrl + c with cleaning after an operation that lasts
package main
import (
"context"
"fmt"
"log"
"os"
"os/signal"
"strconv"
"time"
@innermond
innermond / gist:028dc5b0f9aebb25286a36f661b7de50
Created November 22, 2018 22:56
days of a month in a slice
package main
import (
"fmt"
"time"
)
func main() {
year, m := 2018, time.Month(11)
tfirst := time.Date(year, m, 1, 0, 0, 0, 0, time.UTC)
@innermond
innermond / gist:32f3b3fd275d9385ec9b2d963a9659a0
Created November 22, 2018 22:39
print a basic text version of a year's month
package main
import (
"fmt"
"time"
)
func main() {
year, m := 2018, time.Month(1)
tfirst := time.Date(year, m, 1, 0, 0, 0, 0, time.UTC)
@innermond
innermond / gist:92d43618211a15becc0ba0ff1a499182
Created September 14, 2018 20:01
the other way of reading last line
func readLastLine(f *os.File) (string, error) {
sz, err := f.Seek(0, io.SeekEnd)
if err != nil {
return "", err
}
// ensure we avoid eventually last \n
@innermond
innermond / widget.calculator.js
Created August 1, 2018 09:16
remade of calculator widget as plain js
window.$ = document.getElementById.bind(document);
window.$$ = document.querySelectorAll.bind(document);
Packer = function(w, h) {
this.init(w, h);
};
Packer.prototype = {
init: function(w, h) {
@innermond
innermond / select with dropdown
Created May 1, 2018 20:56
css for styling a select with an arrow
.select {
background-color: white;
display: flex;
flex-wrap: nowrap;
align-items:center;
}
.select:after {
content: "\f078";
font-family: 'FontAwesome';
@innermond
innermond / gist:6bba70c5152b034ac7097825f29a93fa
Created April 3, 2018 15:03
copy and rename a bunch of files
find . -name <Pattern for files from Source Directory> -type f -exec bash -c 'tmp="${1//[\/ ]/-}";cp "{}" <Destination>/${tmp:2}' _ {} \;
@innermond
innermond / .imagery
Created January 26, 2018 07:15
prepare images for pig.js
#!/bin/bash
# useit: ./.imagery <directory source> <dist directory>
# example: ./.imagery ~/Projects/printuridigital.ro/stock-images/pipes/ pipes
from="$1"
root="$2"
p20="$root/20"
p100="$root/100"
p250="$root/250"