Skip to content

Instantly share code, notes, and snippets.

@zyxar
zyxar / exercise.tour.go
Last active October 28, 2025 01:42
tour.golang exercise solutions
/* Exercise: Loops and Functions #43 */
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := float64(2.)
@mmitou
mmitou / Makefile
Created June 26, 2012 17:13
list_head sample
obj-m := listtest.o
INC := /usr/src/kernels/3.4.0-1.fc17.x86_64/include
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) M=$(PWD) modules
check-syntax:
@lonnen
lonnen / gist:3101795
Created July 12, 2012 23:24
git grep and git blame. two great tastes that taste great together
# from i8ramin - http://getintothis.com/blog/2012/04/02/git-grep-and-blame-bash-function/
# runs git grep on a pattern, and then uses git blame to who did it
ggb() {
git grep -n $1 | while IFS=: read i j k; do git blame -L $j,$j $i | cat; done
}
# small modification for git egrep bash
geb() {
git grep -E -n $1 | while IFS=: read i j k; do git blame -L $j,$j $i | cat; done
}
@kachayev
kachayev / go-channels-1-generator.go
Created July 16, 2012 19:42
Channels-driven concurrency with Go
// Channels-driven concurrency with Go
// Code examples from Rob Pike's talk on Google I/O 2012:
// http://www.youtube.com/watch?v=f6kdp27TYZs&feature=youtu.be
//
// Concurrency is the key to designing high performance network services.
// Go's concurrency primitives (goroutines and channels) provide a simple and efficient means
// of expressing concurrent execution. In this talk we see how tricky concurrency
// problems can be solved gracefully with simple Go code.
// (1) Generator: function that returns the channel
@daschl
daschl / couchbase-php-2pc-simple.php
Created July 21, 2012 08:39
Simple Couchbase PHP 2PC Implementation
<?php
/**
* Simple two-phase commit for PHP couchbase.
*
* Michael Nitschinger (@daschl, 2012)
*
* Additional Remarks
* ------------------
* - The Couchbase extension makes it currently pretty hard to write easy readable code when dealing with
* CAS (compared to the ruby adapter). This could certainly be improved with closures. I also found that
@mgroves
mgroves / gist:3265408
Created August 5, 2012 15:31
Using C#'s dynamic to create a DynamicProxy
// from: http://weblogs.asp.net/lichen/archive/2012/08/03/gave-a-presentation-on-c-dynamic-and-dynamic-language-runtime-dlr-at-socal-net-user-group-meeting.aspx
// pros: no requirement for members to be virtual, no need for a 3rd party framework
// cons: loss of static typing benefits (i.e. intellisense & compile time checking), not practical for IoC
class Program
{
static void Main(string[] args)
{
dynamic myObj = new DynamicProxy(new MyClass());
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@tobin
tobin / Makefile
Created October 6, 2012 17:41
cin / scanf comparison
all: xor-c xor-cpp xor-cpp-noflush rand
test: xor-c xor-cpp xor-cpp-noflush
time ./xor-c < rand.txt
time ./xor-cpp < rand.txt
time ./xor-cpp-noflush < rand.txt
rand: rand.c
gcc -Wall rand.c -o rand
@proudlygeek
proudlygeek / cat.go
Created November 4, 2012 16:02
Unix "cat" command in Go
package main
import (
"fmt"
"os"
"io"
"log"
"io/ioutil"
)
@juanique
juanique / git-add-key.sh
Last active November 2, 2024 05:49
Bash script to add a new SSH key to your GitHub account
rm -rf ~/.ssh/id_rsa ~/.ssh/id_rsa.pub
read -p "Enter github email : " email
echo "Using email $email"
ssh-keygen -t rsa -b 4096 -C "$email"
ssh-add ~/.ssh/id_rsa
pub=`cat ~/.ssh/id_rsa.pub`
read -p "Enter github username: " githubuser
echo "Using username $githubuser"
read -s -p "Enter github password for user $githubuser: " githubpass
curl -u "$githubuser:$githubpass" -X POST -d "{\"title\":\"`hostname`\",\"key\":\"$pub\"}" https://api.github.com/user/keys