Skip to content

Instantly share code, notes, and snippets.

validate_license([License|Host]) ->
rpc:call(list_to_atom(string:concat("riak@", string:join(Host, ","))),
walk,
check_license,
[0,0,[License]]).
%dl
%dt=label :file, I18n.t("activerecord.attributes.app.file_label")
%dd
=f.file_field :file
%small.block=form_field_message("app", "file", @version.errors[:file])
%dl
%dt=label :signature, I18n.t("activerecord.attributes.app.file_label")
%dd
=f.file_field :signature
package main
import (
"fmt"
"bufio"
"net"
"io"
)
func main() {
f = IO.binread("avatar.gif")
@parts = []
f.each_char.each_slice(10000).each do |s|
@parts << s.join
end
@text = ""
@parts.each { |chunk| @text << chunk }
package main
import (
"fmt"
"net/http"
"log"
)
type ApiFunc func(w http.ResponseWriter, r *http.Request)
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
gerep / validation.go
Created December 10, 2014 01:15
Go validation
package main
import (
"fmt"
)
type Validation struct {
Error string
OK bool
}
@gerep
gerep / chat
Last active August 29, 2015 14:12
A question I had about slice indexing
<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
#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[])
{
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))