Skip to content

Instantly share code, notes, and snippets.

View naimrajib07's full-sized avatar

Naim Rajiv naimrajib07

View GitHub Profile
@naimrajib07
naimrajib07 / mars_rover.rb
Last active December 21, 2015 08:38
Test Input: 5 5 1 2 N LMLMLMLMM 3 3 E MMRMMRMRRM Expected Output: 1 3 N 5 1 E
class Nasa
attr_accessor :valid_command
attr_accessor :left_command
attr_accessor :right_command
attr_accessor :move_command
attr_accessor :valid_direction
attr_accessor :north_direction
attr_accessor :south_direction
module ActiveAdmin
module Views
class Header < Component
def build(namespace, menu)
super(:id => "header")
@namespace = namespace
@menu = menu
build_custom_nav_bar
__author__ = 'naim'
#http://projecteuler.net/problem=1
def generateSum(rangeVal):
sum = 0
for no in range(1, int(rangeVal)):
if (no % 3 == 0) | (no % 5 == 0):
sum += no
return sum
@naimrajib07
naimrajib07 / stack.py
Created May 23, 2014 06:41
Implementing a Stack in Python And Demonstrate the stack operation.
__author__ = 'naim'
class Stack:
def __init__(self):
self.items = []
def push(self, item):
self.items.append(item)
@naimrajib07
naimrajib07 / queue.py
Created May 23, 2014 09:41
Implementing a Queue in Python
__author__ = 'naim'
class Queue:
def __init__(self):
self.items = []
def enqueue(self, item):
self.items.insert(0, item)
@naimrajib07
naimrajib07 / clouser.py
Created May 28, 2014 11:09
Test closure behavior!
__author__ = 'naim'
def func_outer(outer_arg):
print 'outer'
def func_inner(inner_arg):
print 'inner'
return inner_arg + outer_arg
return func_inner
@naimrajib07
naimrajib07 / functional_pgm.py
Created May 28, 2014 11:11
Test Functional Programming Paradigm!
__author__ = 'naim'
def func1():
return 1
def func2():
return 2
my_funcs = {'a': func1, 'b' : func2 }
@naimrajib07
naimrajib07 / lexical_scoping.py
Created May 28, 2014 11:19
A common pattern that occurs while attempting to use closures, and leads to confusion, is attempting to encapsulate an internal variable using an immutable type. When it is re-assigned in the inner scope, it is interpreted as a new variable and fails because it hasn?t been defined.
__author__ = 'naim'
def iteration():
count = [0] # caution of scoping variable when it is immutable like count = 0, it will local scope for
# iteration() so that used mutable data type like list
def increment_value():
count[0] += 1
return count[0]
return increment_value
@naimrajib07
naimrajib07 / dictionary.py
Created May 28, 2014 11:24
Working with hash/Dictionary in Python
__author__ = 'naim'
class MyClass:
def __init__(self):
self.x = 1
self.my_hash = {'fname': ('n', 'a', 'i', 'm'), 'lname': 'rajib'}
def getVal(self):
return self.x
@naimrajib07
naimrajib07 / lambda_test.py
Created May 28, 2014 11:32
Test lambda behavior in python!
__author__ = 'naim'
squares = []
squares.append(lambda n: n*n) # list have only one element and it's index is 0 and content is lambda!
print squares[0](2)