Skip to content

Instantly share code, notes, and snippets.

View mayra-cabrera's full-sized avatar
💃
Nothing to do here. Go to https://gitlab.com/mayra-cabrera instead

Mayra Cabrera mayra-cabrera

💃
Nothing to do here. Go to https://gitlab.com/mayra-cabrera instead
View GitHub Profile
@mayra-cabrera
mayra-cabrera / ruby_model_example.md
Created January 22, 2016 02:19
ruby_model_example
class Project < ActiveRecord::Base
  belongs_to :portfolio
  has_one :project_manager
  has_many :milestones
  has_many :deliverables, through: milestones
  validates :name, :description, presence: true
  validates :non_disclosure_agreement, acceptance: true
  validates :short_name, uniqueness: true
end
@mayra-cabrera
mayra-cabrera / ruby_irb.md
Last active January 22, 2016 02:10
ruby_irb

Ruby

$ irb
$ irb(main):001:0> exit
$ irb
$ irb(main):001:0&gt; quit
class NumberStrategy
def run
make_a_numeric_operation
end
end
class StringStrategy
def run
check_grammar
end
@mayra-cabrera
mayra-cabrera / buffer-unbuffered-channels.go
Last active November 1, 2015 20:26
Buffer & unbuffered channels
package main
import "fmt"
func main() {
ch_unbuffered := make(chan string)
ch_buffer := make(chan string, 2)
.......
.......
}
func log(msg string){
... some logging code here
}
// Elsewhere in our code after we've discovered an error.
go log("something happened!!")
package main
import (
"fmt"
)
func main() {
orgSlice := make([]string, 5, 8)
orgSlice[0] = "Apple"
orgSlice[1] = "Orange"
package main
import (
"fmt"
)
type IPAddr [4]byte
func (ip IPAddr) String() string {
return fmt.Sprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3])
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
first, second := 0, 1
return func() int{
@mayra-cabrera
mayra-cabrera / exercise-maps.go
Created October 23, 2015 03:56
Exercise-maps
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
array := strings.Fields(s)
count := make(map[string]int)