Skip to content

Instantly share code, notes, and snippets.

@jaybill
jaybill / copytree.go
Created June 5, 2012 17:46
How to copy a directory tree (preserving permissions) in Go.
package main
import "fmt"
import "os"
import "io"
import "io/ioutil"
import "log"
// Copies file source to destination dest.
func CopyFile(source string, dest string) (err error) {
@cam-gists
cam-gists / Generic CodeIgniter Model
Created July 13, 2012 21:37 — forked from timmahoney/Generic CodeIgniter Model
Codeigniter: PHP: Table Model
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Generic CodeIgniter Database Model - One table version
*
* Set your Database table and table fields at the top,
* and screw creating models for interfacing with one table.
*
* Disclaimer: I'll answer questions or whatever, but I'm creating
* this to speed my own development up. I hope it helps, but it's not supported.
@furkanmustafa
furkanmustafa / html-php-date-picker.php
Created January 27, 2013 15:34
Date Picker Select Generator for HTML & PHP
<select name="year">
<option value="">Year</option>
<?php for ($year = date('Y'); $year > date('Y')-100; $year--) { ?>
<option value="<?php echo $year; ?>"><?php echo $year; ?></option>
<?php } ?>
</select>
<select name="month">
<option value="">Month</option>
<?php for ($month = 1; $month <= 12; $month++) { ?>
<option value="<?php echo strlen($month)==1 ? '0'.$month : $month; ?>"><?php echo strlen($month)==1 ? '0'.$month : $month; ?></option>
@jackdoe
jackdoe / bot.go
Last active December 26, 2015 15:19
golang map[string]bool{} based user agent detect
// took the list from:
// http://www.phacks.net/detecting-search-engine-bot-and-web-spiders/
// and made it a map[string]bool
var BOTS = map[string]bool{
"Baiduspider+(+http://www.baidu.com/search/spider.htm": true,
"Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)": true,
"Moreoverbot/5.1 (+http://w.moreover.com; webmaster@moreover.com) Mozilla/5.0": true,
"UnwindFetchor/1.0 (+http://www.gnip.com/)": true,
"Voyager/1.0": true,
@icambridge
icambridge / interface.go
Last active November 1, 2017 00:59
Observer pattern - golang
type TestCallBack struct {
}
func (c *TestCallBack) Exec(o *Observable) {
log.Println(o.Name)
}
type Callback interface {
Exec(h *Observable)
@machupicchubeta
machupicchubeta / convert_snakecase_to_camelcase_in_c#
Created April 7, 2014 07:32
convert snake case to camel case in c#
"foo_bar".Split(new [] {"_"}, StringSplitOptions.RemoveEmptyEntries).Select(s => char.ToUpperInvariant(s[0]) + s.Substring(1, s.Length - 1)).Aggregate(string.Empty, (s1, s2) => s1 + s2);
@francoishill
francoishill / visitor_pattern_in_go.go
Last active April 12, 2020 20:45
Visitor Pattern in Golang
package main
//Thanks to http://ecs.victoria.ac.nz/foswiki/pub/Main/TechnicalReportSeries/ECSTR11-01.pdf
import (
"fmt"
)
//We will have multiple car parts
type CarPart interface {
Accept(CarPartVisitor)
@jpillora
jpillora / sshd.go
Last active December 17, 2023 16:27
Go SSH server complete example - Read more here https://blog.gopheracademy.com/go-and-ssh/
// A small SSH daemon providing bash sessions
//
// Server:
// cd my/new/dir/
// #generate server keypair
// ssh-keygen -t rsa
// go get -v .
// go run sshd.go
//
// Client:
@vsouza
vsouza / .bashrc
Last active June 14, 2024 08:45
Golang setup in Mac OSX with HomeBrew. Set `GOPATH` and `GOROOT` variables in zshell, fish or bash.
# Set variables in .bashrc file
# don't forget to change your path correctly!
export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
@philipz
philipz / gist:67892bdc8a385ecb3b8c
Last active November 14, 2017 22:57
Rsync & Docker save

Rsync & Docker save

docker save $1 > $1.tar && rsync -ravP -e ssh $1.tar philipz@192.168.2.51:/home/philipz/tmp && rm $1.tar ##Add Gzip docker save busybox | gzip -c - > busybox.tar.gz

gzip -d busybox.tar.gz && docker load < busybox.tar

docker save busybox | gzip | pv | ssh -i ~/.ssh/id_rsa USER@HOSTNAME sudo docker load