Skip to content

Instantly share code, notes, and snippets.

View flaviocopes's full-sized avatar

Flavio Copes flaviocopes

View GitHub Profile
@flaviocopes
flaviocopes / convert-temperatures.go
Last active July 16, 2017 09:40
Go: converting temperatures without type aliases (version with type aliases in https://gist.github.com/flaviocopes/2b1f45c510a0e90d703c0aeabe3b0492)
package tempconv
const (
AbsoluteZeroC float64 = -273.15
FreezingC float64 = 0
BoilingC float64 = 100
)
func CToF(c float64) float64 { return float64(c*9/5 + 32) }
@flaviocopes
flaviocopes / types-aliases.go
Last active July 16, 2017 09:41
Go: declaring types aliases #golang
package tempconv
import "fmt"
type Celsius float64
type Fahrenheit float64
const (
AbsoluteZeroC Celsius = -273.15
FreezingC Celsius = 0
function (user, context, callback) {
if (context.clientName !== 'YOURAPPNAME') {
return callback(null, user, context);
}
var whitelist = ['info@example.com', 'owner@example.org']; //authorized emails
var userHasAccess = whitelist.some(
function (email) {
return user.email.toLowerCase() === email;
});
@flaviocopes
flaviocopes / sender.js
Created November 23, 2018 11:08
PeerJS photo sharing example - sender
document.addEventListener('DOMContentLoaded', event => {
const peer = new Peer('sender', { host: 'localhost', port: 9000, path: '/' })
const conn = peer.connect('receiver')
document.querySelector('input').onchange = function(event) {
const file = event.target.files[0]
const blob = new Blob(event.target.files, { type: file.type })
conn.send({
@flaviocopes
flaviocopes / receiver.js
Created November 23, 2018 11:08
PeerJS photo sharing example - receiver
document.addEventListener('DOMContentLoaded', event => {
const peer = new Peer('receiver', {
host: 'localhost',
port: 9000,
path: '/'
})
peer.on('connection', conn => {
conn.on('data', data => {
if (data.filetype.includes('image')) {
@flaviocopes
flaviocopes / netlify.toml
Created July 19, 2018 06:23
Netlify configuration file for Hugo
[build]
publish = "public"
command = "hugo"
[context.production.environment]
HUGO_VERSION = "0.43"
HUGO_ENV = "production"
HUGO_ENABLEGITINFO = "true"
[context.split1]
@flaviocopes
flaviocopes / intro.md
Last active December 23, 2019 06:42 — forked from derhuerst/intro.md
Installing Git on Linux, Mac OS X and Windows https://www.writesoftware.org/topic/git
const ws = new WebSocket('ws://localhost:8080')
ws.onopen = () => {
console.log('Connected to the signaling server')
}
ws.onerror = err => {
console.error(err)
}
@flaviocopes
flaviocopes / check-substring-ends-with.go
Last active November 15, 2021 09:34
Go: check if a string ends with a substring #golang
package main
import (
"strings"
)
func main() {
strings.HasSuffix("foobar", "bar") // true
}
@flaviocopes
flaviocopes / check-substring-starts-with.go
Last active April 16, 2023 03:02
Go: check if a string starts with a substring #golang
package main
import (
"strings"
)
func main() {
strings.HasPrefix("foobar", "foo") // true
}