Skip to content

Instantly share code, notes, and snippets.

View licenses.erl
validate_license([License|Host]) ->
rpc:call(list_to_atom(string:concat("riak@", string:join(Host, ","))),
View _form.html.haml
%dt=label :file, I18n.t("")
=f.file_field :file
%small.block=form_field_message("app", "file", @version.errors[:file])
%dt=label :signature, I18n.t("")
=f.file_field :signature
View server.go
package main
import (
func main() {
View cut_the_hope.rb
f = IO.binread("avatar.gif")
@parts = []
f.each_char.each_slice(10000).each do |s|
@parts << s.join
@text = ""
@parts.each { |chunk| @text << chunk }
View routes.go
package main
import (
type ApiFunc func(w http.ResponseWriter, r *http.Request)
View remove_from_slice.go
func main() {
scores := []int{1,2,3,4,5}
scores = removeAtIndex(scores, 2)
func removeAtIndex(source []int, index int) []int {
source = append(source[:index], source[index+1:]...)
return source
gerep / validation.go
Created December 10, 2014 01:15
Go validation
View validation.go
package main
import (
type Validation struct {
Error string
OK bool
gerep / chat
Last active August 29, 2015 14:12
A question I had about slice indexing
View chat
<gerep> andlabs, the element 0 is "g", 1 is "o", etc. When I do [1:4] it will return "g" as the element at position one because it counts the slice starting from zero. If I'm expecting the count to start from 0, the element at position 4 would be "n" and not "a"
<gerep> andlabs, and this way, for 4 to be "a", the slice count has to start from 1: position 1 = "g", 2 = "o", etc
<andlabs> the element at position 4 starting at 0 is n
<gerep> andlabs, yes!
<andlabs> ut that 4 is the first element /after the end of the slice/
<andlabs> so you get everything from 1 /up to but not including/ 4
<gerep> andlabs, yes, and why not use [1:3] ?
<gerep> andlabs, because the 1 is included but the 4 is not
<andlabs> because this type of coordinate specification is easier to reason about
<andlabs> how many elements are in the slice? 4-1=3
View pointer_size.c
#include <stdio.h>
#include <stdlib.h>
void test(int *vet)
printf("depois %lu\n", ( sizeof(vet)/ sizeof(vet[0])) );
int main(int argc, char const *argv[])
View coinsforusers.go
package main
import "fmt"
var (
coins = 50
users = []string{
"Matthew", "Sarah", "Augustus", "Heidi", "Emilie",
"Peter", "Giana", "Adriano", "Aaron", "Elizabeth",
distribution = make(map[string]int, len(users))