Skip to content

Instantly share code, notes, and snippets.

@nikita8
nikita8 / infinite_loop.go
Created August 23, 2019 19:22
Infinite loop in go
//Go
for {
// do something
}
@nikita8
nikita8 / if-else.go
Last active November 14, 2018 07:35
if else condition
// go
num := 9
if num < 0 {
fmt.Printf("%d is negative", num)
} else if num < 10 {
fmt.Printf("%d has 1 digit", num)
} else {
fmt.Printf("%d has multiple digits", num)
}
@nikita8
nikita8 / go-routine.go
Created November 13, 2018 05:23
go Routine
package main
import(
"fmt"
"time"
)
func f(from string) {
for i := 0; i < 3; i++ {
time.Sleep(1 * time.Millisecond)
@nikita8
nikita8 / json_decoding.rb
Created November 13, 2018 05:16
JSON decoding in Ruby
#ruby
str = `{"page": 1, "fruits": ["apple", "peach"]}`
JSON.parse(str)
@nikita8
nikita8 / json-decoding.go
Last active November 14, 2018 08:38
JSON decoding in GO
// Go
package main
import (
"encoding/json"
"fmt"
)
// Go
type response struct {
@nikita8
nikita8 / json_encoding.rb
Created November 13, 2018 05:15
JSON encoding in Ruby
#Ruby
hash = {apple: 5, lettuce: 7}
#encoding hash to json
json_data = hash.to_json
puts json_data
@nikita8
nikita8 / json-encoding.go
Last active November 14, 2018 08:39
JSON encoding in GO
// Go
package main
import (
"encoding/json"
"fmt"
)
func main() {
@nikita8
nikita8 / private_method.rb
Last active November 13, 2018 05:12
Private method in Ruby
#Ruby
class User
attr_accessor :user_name
def initialize(user_name, password)
@user_name = user_name
@password = password
end
def get_user_password
@nikita8
nikita8 / private-method.go
Created November 13, 2018 05:11
Private Method in Go
// Go
type User struct {
Username string
password string
}
func (u User) GetPassword() string{
return u.secretPassword()
}
@nikita8
nikita8 / oop.rb
Created November 13, 2018 05:08
OOP in ruby
# Ruby
class Festival
def initialize(name, description)
@name = name
@description = description
end
def is_dashain?
if @name == "Dashain"
@description = "Let's fly kites."