Skip to content

Instantly share code, notes, and snippets.

@gerep
gerep / responseChannel.go
Created February 28, 2016 13:15
Using a channel to get a response from a goroutine
package main
import (
"fmt"
"net/http"
)
type work struct {
url string
resp chan *http.Response
@gerep
gerep / heartbeat.go
Created February 28, 2016 13:07
Heartbeat example
package main
import (
"fmt"
"time"
)
func main() {
heartbeat := time.Tick(1 * time.Second)
for {
@gerep
gerep / sed.bash
Last active February 25, 2016 20:49
This sed command will search for the tab <KEY>. count 12 characters and replace them with *. The same happens with the tag <KEYVAL>
sed -e 's/<KEY>[0-9]\{12\}/(&)/g' -e 's/(<KEY>.*)/<KEY>*************/g' -i blah.log
sed -e 's/<KEYVAL>[0-9]\{12\}/(&)/g' -e 's/(<KEYVAL>.*)/<KEYVAL>*************/g' -i blah.log
@gerep
gerep / FastestCDN.go
Created February 23, 2016 16:43
Using channels to test the fastest CDN response
package main
import (
"fmt"
"net/http"
)
type response struct {
name string
resp *http.Response
@gerep
gerep / UniqueNumberWithChannels.go
Created February 23, 2016 16:20
Using channels to return a unique number
package main
import "fmt"
func main() {
id := make(chan string)
go func() {
var counter int64
for {
@gerep
gerep / search.bash
Last active February 12, 2016 17:49
#! /usr/bin/env bash
#
# search [file(s)]
#
# This script will read the files passed as parameters and those files
# will contain a list of IPs separated by lines and will search for
# each of those IPs in both omg-switch log files
#
# When no argument is passed, it will open the page on the current branch
class TransactionCost < ActiveRecord::Base
belongs_to :company
belongs_to :app
has_many :range_costs
accepts_nested_attributes_for :range_costs, allow_destroy: true, reject_if: lambda { |a| a[:to].blank? && a[:from].blank? && a[:cost].blank? }
validates :app_id, uniqueness: true
validates :range_costs, presence: true
# READS A .yml FILE AND FOR EACH KEY IT WILL CREATE A GETTER AND SETTER METHODS
class Flag
def initialize
@yaml = Psych.load_file('config/flags.yml')
@yaml.each_key do |item|
self.class.send(:define_method, item) { @yaml[item] }
self.class.send(:define_method, "#{item}=") { |value| @yaml[item] = value }
end
end
end
package main
import (
"strings"
"fmt"
)
func WordCount(s string) map[string]int {
words := strings.Fields(s)
counter := map[string]int{}
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))