Skip to content

Instantly share code, notes, and snippets.

@kendellfab
kendellfab / role.go
Created June 9, 2022 13:02
Go Enums
type Role int
const (
RoleUnknown Role = iota
_
_
RoleUser
_
_
RoleAdmin
import (
"context"
"net/http"
)
type key int
var contextKey = key(22)
func SetUser(usr *User, r *http.Request) {
// KTTime is an example of a type that is aliased to time, than implements the json marshaling functions.
// This is an example for how to build serialization interopability with kotlin/gson.
package kttime
type KTTime time.Time
func (t KTTime) MarshalJSON() ([]byte, error) {
gt := time.Time(t)
f := gt.Format(ktFormat)
return json.Marshal(f)
@kendellfab
kendellfab / synergy_build
Created December 1, 2014 15:41
Building Synergy on OSX Yosemite
I was able to get this working on Yosemite with the following command:
./hm.sh conf -g2 --mac-sdk 10.10 --mac-identity Yosemite
Of course, this will only work given you have the dependencies. You can install them with the Homebrew package manager.
brew install cmake qt
Additionally, you'll want to build it with:
./hm.sh build
And finally, to install it, you'll get the compiled results from the bin folder, i.e. Synergy.app
@kendellfab
kendellfab / fedora_mp3
Created December 14, 2013 02:40
Fedora MP3 support
rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm
rpm -Uvh http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
yum install gstreamer-plugins-ugly gstreamer-plugins-bad gstreamer-ffmpeg
## java ##
alternatives --install /usr/bin/java java /usr/java/latest/jre/bin/java 200000
## javaws ##
alternatives --install /usr/bin/javaws javaws /usr/java/latest/jre/bin/javaws 200000
@kendellfab
kendellfab / mysql_user
Created December 3, 2013 16:36
New User
GRANT ALL PRIVILEGES ON dbTest.* To 'user'@'hostname' IDENTIFIED BY 'password';
@kendellfab
kendellfab / golang_time
Created November 20, 2013 23:07
Golang time function.
func timeTrack(start time.Time, name string) {
elapsed := time.Since(start)
log.Printf("%s took %s", name, elapsed)
}
func factorial(n *big.Int) (result *big.Int) {
defer timeTrack(time.Now(), "factorial")
// ... do some things, maybe even return under some condition
return n
}
@kendellfab
kendellfab / git_retieve
Created November 13, 2013 22:06
Retrieve lost file from git.
git checkout <rev> filename
@kendellfab
kendellfab / read_line.go
Created November 11, 2013 17:41
Golang --> Read file line by line.
func readLine(path string) {
inFile, _ := os.Open(path)
defer inFile.Close()
scanner := bufio.NewScanner(inFile)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
fmt.Println(scanner.Text())
}
}
@kendellfab
kendellfab / golang_concurrency
Created November 4, 2013 21:31
Simple Golang concurrency concept.
// http://talks.golang.org/2012/concurrency.slide
func Google(query string) (results []Result) {
c := make(chan Result)
go func() { c <- Web(query) } ()
go func() { c <- Image(query) } ()
go func() { c <- Video(query) } ()
for i := 0; i < 3; i++ {
result := <-c
results = append(results, result)