Skip to content

Instantly share code, notes, and snippets.

View ndabAP's full-sized avatar
🔭

Julian Claus ndabAP

🔭
View GitHub Profile
func CreatePDFFromHTML(inputHTML []byte) ([]byte, error) {
dirName, err := ioutil.TempDir("", "pdf-generator")
if err != nil {
return nil, err
}
// remove this and log the dirName if you need to debug the HTML
defer os.RemoveAll(dirName)
// log.Println(dirName)
@ndabAP
ndabAP / index.js
Last active January 18, 2020 10:47
Convert seconds into format HH:MM:SS in JavaScript. Works for negative values as well
function nSecToTime(s) {
let seconds = s
s = Math.abs(s)
let t = [0, 0, 0]
let r = s % 3600
t[0] = Math.floor(s / 3600)
t[1] = Math.floor(r / 60)
r = r % 60
package main
import (
"encoding/csv"
"image/color"
"os"
"sort"
"strconv"
"gonum.org/v1/plot"
@fracasula
fracasula / cond.go
Created August 3, 2018 14:11
GoLang: How to use sync.Cond
package main
import (
"sync"
"fmt"
"time"
)
func main() {
lock := sync.Mutex{}
@mauri870
mauri870 / tf-serving-client.go
Last active April 2, 2022 08:43
Tensorflow Serving Go client for the inception model
// Tensorflow Serving Go client for the inception model
// go get github.com/golang/protobuf/ptypes/wrappers google.golang.org/grpc
//
// Compile the proto files:
//
// git clone https://github.com/tensorflow/serving.git
// git clone https://github.com/tensorflow/tensorflow.git
//
// mkdir -p vendor
@travisjeffery
travisjeffery / functional-options.md
Last active April 23, 2023 11:13
How to do functional options in Golang

Here's the simplest example showing how to do functional options in Golang.

They're a great way to enable users to set options and ease adding new options later.

package main

import (
	"flag"
	"fmt"
@thornbill
thornbill / .gitlab-ci.yml
Created November 22, 2016 21:29
Example Node GitLab CI Yamlfile
# Official framework image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/node/tags/
image: node:6
before_script:
- npm install
# This folder is cached between builds
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache
cache:
@kangax
kangax / quicksort.hs
Last active September 5, 2021 19:44
Haskell-inspired quick sort in ES6
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallerSorted = quicksort (filter (<=x) xs)
biggerSorted = quicksort (filter (>x) xs)
in smallerSorted ++ [x] ++ biggerSorted
@mdwhatcott
mdwhatcott / custom_json.go
Created July 29, 2015 17:15
Example of implementing MarshalJSON and UnmarshalJSON to serialize and deserialize custom types to JSON in Go. Playground: http://play.golang.org/p/7nk5ZEbVLw
package main
import (
"bytes"
"encoding/json"
"fmt"
"strconv"
)
func main() {
@svanellewee
svanellewee / mongodb node.js stream.js
Created July 4, 2015 22:05
Node js streams with mongo and filter transforms! note the ???ObjectMode settings!
var mongodb = require("mongodb");
var MongoClient = mongodb.MongoClient;
var fs = require("fs");
var Transform = require("stream").Transform;
var name_surname_email_filter = new Transform({readableObjectMode:true, writableObjectMode:true} );
name_surname_email_filter._transform = function(data, enc, cb) {
//console.log(data);
var newdata = { first_name: data.first_name,