Skip to content

Instantly share code, notes, and snippets.

@paulmach
paulmach / serve.go
Last active May 17, 2024 20:37
Simple Static File Server in Go
/*
Serve is a very simple static file server in go
Usage:
-p="8100": port to serve on
-d=".": the directory of static files to host
Navigating to http://localhost:8100 will display the index.html or directory
listing file.
*/
package main
@hyg
hyg / gist:9c4afcd91fe24316cbf0
Created June 19, 2014 09:36
open browser in golang
func openbrowser(url string) {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
@timrwood
timrwood / moment-immutable.js
Created September 16, 2014 17:16
Immutable Moments
(function (root, factory) {
"use strict";
if (typeof define === 'function' && define.amd) {
define(['moment'], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require('moment'));
} else {
factory(root.moment);
}
}(this, function (moment) {
@paulirish
paulirish / bling.js
Last active May 1, 2024 19:56
bling dot js
/* bling.js */
window.$ = document.querySelectorAll.bind(document);
Node.prototype.on = window.on = function (name, fn) {
this.addEventListener(name, fn);
}
NodeList.prototype.__proto__ = Array.prototype;
@karl-gustav
karl-gustav / Fronter rosetta stone.md
Last active February 22, 2016 11:50
Fronter rosetta stone
English Spanish Norwegian
I live in the municipality of Oslo Vivo en el municipio de Oslo Jeg bor i Oslo kommune
My glass is half full Mi vaso está medio lleno glasset mitt er halvfullt
I agree Estoy de acuerdo Jeg er enig
See you later Nos vemos Vi sees / snakkes
@andrewmilson
andrewmilson / file-upload-multipart.go
Last active May 20, 2024 14:46
Golang multipart/form-data File Upload
package main
import (
"net/http"
"os"
"bytes"
"path"
"path/filepath"
"mime/multipart"
"io"
@bahmutov
bahmutov / README.md
Last active October 4, 2023 08:35
Single command to run Node with local file access

Goal: run a simple NodeJS application inside a Docker container

Subgoal: give it access to local files.

docker run -it --rm --name example -v "$PWD":/usr/src/app -w /usr/src/app node:5-slim node index.js

output:

@jaymecd
jaymecd / redirectExample.go
Created October 11, 2016 21:20 — forked from d-schmidt/redirectExample.go
How to redirect HTTP to HTTPS with a golang webserver.
package main
import (
"net/http"
)
func redirect(w http.ResponseWriter, req *http.Request) {
http.Redirect(w, req,
"https://" + req.Host + req.URL.String(),
http.StatusMovedPermanently)
}
@nrollr
nrollr / nginx.conf
Last active May 11, 2024 16:31
NGINX config for SSL with Let's Encrypt certs
# UPDATED 17 February 2019
# Redirect all HTTP traffic to HTTPS
server {
listen 80;
listen [::]:80;
server_name www.domain.com domain.com;
return 301 https://$host$request_uri;
}
# SSL configuration
@karl-gustav
karl-gustav / git_setup.sh
Last active May 9, 2023 06:36
My git setup
git config --global init.defaultBranch main
git config --global alias.clone 'clone'
git config --global alias.br 'branch'
git config --global alias.st 'status'
git config --global alias.co 'checkout'
git config --global alias.ci 'commit'
git config --global alias.pr 'pull --rebase'
git config --global alias.pa 'pull --abort'
git config --global alias.rc 'rebase --continue'
git config --global alias.rs 'rebase --skip'