Skip to content

Instantly share code, notes, and snippets.

@nikita8
nikita8 / gist:5548444
Created May 9, 2013 16:09
last monday from current date
function getMonday(d) {
d = new Date(d);
var day = d.getDay(),
diff = d.getDate() - day + (day == 0 ? -6:1); // adjust when day is sunday
return new Date(d.setDate(diff));
}
getMonday(new Date());
def happy_number(number)
sum_of_digits = []
flag = true
while(number != 1)
number = digits_square_sum(number)
if sum_of_digits.include?(number)
flag = false
break
else
sum_of_digits << number
@nikita8
nikita8 / curious_numbers.rb
Last active August 28, 2018 11:38
WCC W03::C01 Curious Number
def curious_numbers
curious_number_list = []
(1..9999999999).each_slice(100000).each do |numbers|
numbers.each do |number|
square = number ** 2
number_of_digit = number.to_s.length
if(square.to_s[-number_of_digit..-1].to_i == number)
curious_number_list << number
end
end
@nikita8
nikita8 / generate_acronym.go
Last active October 8, 2018 10:18
W06::C01 Generate acronym from the input string
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
@nikita8
nikita8 / hello_world.rb
Created November 13, 2018 03:51
RubyHelloWorld
puts "Hello World!!!"
@nikita8
nikita8 / hello-world.go
Last active November 13, 2018 03:54
HelloWorldInGo
package main
// similar to require in ruby
import "fmt"
func main(){
fmt.Println("Hello World!!!")
}
@nikita8
nikita8 / ruby_comment.rb
Last active November 13, 2018 04:03
CommentingInRuby
puts "Commenting Code in Ruby"
# this is single line comment in ruby
=begin
This is multiline
Comment in ruby
=end
@nikita8
nikita8 / go-comment.go
Created November 13, 2018 04:04
CommentingInGo
package main
import "fmt"
func main(){
fmt.Println("Commenting in Go")
// this is single line comment in Go
/* this is multiline
Comment in Go */
}
@nikita8
nikita8 / each_loop.rb
Created November 13, 2018 04:56
Each loop in ruby
#Ruby
{name: 'Nikita', lastname: 'Acharya'}.each do |k, v|
puts k, v
end
@nikita8
nikita8 / each_loop.go
Created November 13, 2018 04:57
Each loop in go
// Go
kvs := map[string]string{"name": "Nikita", "lastname": "Acharya"}
for k, v := range kvs {
fmt.Printf("%s -> %s\n", k, v)
}