Skip to content

Instantly share code, notes, and snippets.

View flaviocopes's full-sized avatar

Flavio Copes flaviocopes

View GitHub Profile
@flaviocopes
flaviocopes / receiver.js
Created November 23, 2018 11:08
PeerJS photo sharing example - receiver
View receiver.js
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 / sender.js
Created November 23, 2018 11:08
PeerJS photo sharing example - sender
View sender.js
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({
View client.js
const ws = new WebSocket('ws://localhost:8080')
ws.onopen = () => {
console.log('Connected to the signaling server')
}
ws.onerror = err => {
console.error(err)
}
@flaviocopes
flaviocopes / netlify.toml
Created July 19, 2018 06:23
Netlify configuration file for Hugo
View netlify.toml
[build]
publish = "public"
command = "hugo"
[context.production.environment]
HUGO_VERSION = "0.43"
HUGO_ENV = "production"
HUGO_ENABLEGITINFO = "true"
[context.split1]
View email.js
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 / 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
View intro.md
View Visualize your local Git contributions with Go.md

Run go install and

  • gogitlocalstats -add /path/to/folder will scan that folder and its subdirectories for repositories to scan
  • gogitlocalstats -email your@email.com will generate a CLI stats graph representing the last 6 months of activity for the passed email. You can configure the default in main.go, so you can run gogitlocalstats without parameters.

Being able to pass an email as param makes it possible to scan repos for collaborators activity as well.

License: CC BY-SA 4.0

@flaviocopes
flaviocopes / go-sort-map.go
Last active December 25, 2023 21:03
Go: sort a Map by key #golang
View go-sort-map.go
import "sort"
ages := map[string]int{
"a": 1,
"c": 3,
"d": 4,
"b": 2,
}
names := make([]string, 0, len(ages))
@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)
View convert-temperatures.go
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
View types-aliases.go
package tempconv
import "fmt"
type Celsius float64
type Fahrenheit float64
const (
AbsoluteZeroC Celsius = -273.15
FreezingC Celsius = 0