Skip to content

Instantly share code, notes, and snippets.

View ta1kt0me's full-sized avatar
🐢
slow

ta1kt0me

🐢
slow
View GitHub Profile
@ta1kt0me
ta1kt0me / add_frozen_string_literal_comment.rb
Last active May 29, 2022 13:33
Add frozen string literal comment into generated files in rails v5.1.0
module AddFrozenStringLiteralComment
def add_frozen_string_literal_comment(dist)
if File.exist?(dist) && File.extname(dist) == '.rb'
File.open(dist, 'r') do |f|
body = f.read
File.open(dist, 'w') do |new_f|
new_f.write("# frozen_string_literal: true\n" + body)
end
end
@ta1kt0me
ta1kt0me / swagger_client_generator.rb
Created January 28, 2017 01:48
Swagger client generator
require 'yaml'
require 'active_support/core_ext/string/inflections'
require 'byebug'
class SwaggerClientClassBuilder
attr_accessor :path, :method_builders
def initialize
@method_builders = []
end
class Author < ApplicationRecord
has_many :books
end
@ta1kt0me
ta1kt0me / gista-file
Last active January 26, 2017 17:10
Exercise: Web Crawler
package main
import (
"fmt"
"sync"
)
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
@ta1kt0me
ta1kt0me / ExerciseEquivalentBinaryTrees.go
Last active January 23, 2017 15:45
Exercise: Equivalent Binary Trees
package main
import (
"fmt"
"golang.org/x/tour/tree"
)
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int) {
@ta1kt0me
ta1kt0me / ExerciseImages.go
Last active January 22, 2017 16:15
Exercise: Images
package main
import (
"golang.org/x/tour/pic"
"image"
"image/color"
)
type Image struct {
w int
@ta1kt0me
ta1kt0me / ExerciseRot13Reader.go
Created January 22, 2017 14:46
Exercise: rot13Reader
package main
import (
"io"
"os"
"regexp"
"strings"
)
type rot13Reader struct {
@ta1kt0me
ta1kt0me / ExerciseReaders.go
Created January 22, 2017 08:03
Exercise: Readers
package main
import (
"golang.org/x/tour/reader"
)
type MyReader struct{}
func (t MyReader) Read(b []byte) (int, error) {
b[0] = 'A'
@ta1kt0me
ta1kt0me / CreateSliceWithSomeConditionFromArray.go
Created January 22, 2017 07:59
Create slice filtering some condition from array
package main
import "fmt"
func main() {
s := []int{2, 3, 5, 7, 11, 13}
printSlice(s)
// https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating
ns := s[:0]
@ta1kt0me
ta1kt0me / ExerciseErrors.go
Created January 22, 2017 07:34
Exercise: Errors
package main
import (
"fmt"
)
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) Error() string {
// unless cast to float64, e call Error() method again to call fmt.Print(e)