Skip to content

Instantly share code, notes, and snippets.

View BolajiOlajide's full-sized avatar

Bolaji Olajide BolajiOlajide

View GitHub Profile
class Andela:
fellows = 'top .5 percent in Nigeria'
fellow_list = [1,2,3,4,5]
@staticmethod
def say_the_chant():
print "Andela Aww Yea!!!!"
class Singleton:
the_actual_instance = None
class _Singleton:
"""
The actual implementation of the Singleton class should reside here
"""
def __init__(self):
self.required_attribute = 'mayor'
print('this should only be printed once.. i.e this class should only be instantiated once.')
@BolajiOlajide
BolajiOlajide / power-recursive.py
Last active April 6, 2017 06:02
Python Recursive Function 1
def power(a,b):
if b == 0:
return 1
elif a == 0:
return 0
else:
return a * power(a,b-1)
@BolajiOlajide
BolajiOlajide / factorial-recursive.py
Last active April 6, 2017 05:53
Python Recursive Function 2
def factorial(num):
if num == 0:
return 1
else:
return num * factorial(num - 1)
@BolajiOlajide
BolajiOlajide / power-recursive.js
Last active April 10, 2017 07:14
Recursice Javascript Function
function power(a,b){
if (b === 0){
return 1
}
else if (a === 0){
return 0
}
else{
return a * power(a,b-1)
}
@BolajiOlajide
BolajiOlajide / recursion.js
Created April 10, 2017 07:02
Recursive Factorial Function
function factorial( n ) {
if ( n === 1 ) {
return 1;
}
return n * factorial( n - 1 );
}
class Human {
constructor(name, id){
this.name = name;
this.id = id;
}
}
one = new Human('bolaji',1);
two = new Human('murphy', 1);
three = new Human('anu',3);
@BolajiOlajide
BolajiOlajide / ES5 Classes.js
Last active May 10, 2017 21:37
Different ways of defining classes in ES5 and also how to inherit from another class
// class
var Person = function(name, gender) {
this.name = name;
this.gender = gender;
this.legs = 2;
}
Person.prototype.getName = function () {
return this.name;
}
@BolajiOlajide
BolajiOlajide / sample_array.py
Created May 15, 2017 20:32
Array Data Checker
sample_array = ['Bolaji','Damilola','Ichiato','Oladipupo','Koya','Mumeen']
# I want to cycle through the array an check if an element is there.
# Here i want to see if 'Bolaji' is in the sample_array
def name_exists(name):
for element in sample_array:
if element == name:
print("Bolaji Exists")
@BolajiOlajide
BolajiOlajide / dispatch.js
Last active June 21, 2017 18:48
Manually dispatching actions
import React from "react";
import PropTypes from "prop-types";
import {connect} from "react-redux";
import * as courseActions from "../../actions/courseAction";
class CoursesPage extends React.Component {
constructor(props) {
super(props);
this.state = {