Skip to content

Instantly share code, notes, and snippets.

View tejuafonja's full-sized avatar

Afonja Tejumade tejuafonja

View GitHub Profile
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Flex</title>
<style>
#container {
display: flex;
flex-wrap: wrap;
justify-content: center;
# python 2.7
def collatz(number):
if number % 2 == 0:
print number // 2
return number // 2
elif number % 2 == 1:
result = (3 * number + 1)
print result
return result
# python 2.7
class Celsius(object):
def __init__(self, temperature = 0):
self.temperature = temperature
def to_fahrenheit(self):
return (self.temperature * 1.8) + 32
@property
def temperature(self):
grid = [['.', '.', '.', '.', '.', '.'],
['.', 'O', 'O', '.', '.', '.'],
['O', 'O', 'O', 'O', '.', '.'],
['O', 'O', 'O', 'O', 'O', '.'],
['.', 'O', 'O', 'O', 'O', 'O'],
['O', 'O', 'O', 'O', 'O', '.'],
['O', 'O', 'O', 'O', '.', '.'],
['.', 'O', 'O', '.', '.', '.'],
['.', '.', '.', '.', '.', '.']]
@tejuafonja
tejuafonja / Objects and Array
Created October 6, 2017 11:38
How to copy an object or array
var player = {score: 1, name: 'Jeff'};
var newPlayer = Object.assign({}, player, {score: 2});
// Now player is unchanged, but newPlayer is {score: 2, name: 'Jeff'}
// Or if you are using object spread syntax proposal, you can write:
var newPlayer = {...player, score: 2};
// for Arrays
var player = ['Ronaldo', 'Merci', 'Rooney']
@tejuafonja
tejuafonja / Binary Gap
Created October 13, 2017 16:57
find the max 0's in-between 1's in a binary number
function solution(N) {
var maxGap = 0;
var tempGap = 0;
var count = 0;
var binGap = N.toString(2);
var lastIndex = binGap.length - 1;
for (lastIndex; lastIndex>=0; lastIndex--) {
if (binGap[lastIndex] !== '0') {
function staircase(n) {
for (var i=0; i<n; i++) {
var space = n-i-1
var stairs = ' '.repeat(space) + '#'.repeat(i+1)
console.log(stairs)
}
}
// is a==1&&a==2&&a==3 = true?
const a = {
currentVal: 0,
valueOf: function() {
return this.currentVal += 1;
}
}
if (a==1&&a==2&&a==3) {
@tejuafonja
tejuafonja / setup
Created March 16, 2018 12:44
Running Ghost on github pages
download ghost (see https://medium.com/aishik/publish-with-ghost-on-github-pages-2e5308db90ae)
install node
extract ghost to /home or anywhere you'd remember. maybe /home/my-ghost or /home/ghost. You can use any name you want
run knex-migrator init
run npm install
run npm start
checkout your server on http://localhost:2368/ #everything should work fine
CNTRL-C # kill the server
buster setup YOUR-FORK-REPO
@tejuafonja
tejuafonja / 1 Introduction to sass - scss
Last active April 4, 2018 18:55
Working with Scss / Sass
Sass is CSS pre-processor that allows you to
a. Use variables
b. Nest CSS - this helps you have neat structure
c. Seperate your CSS to modules (partials)
d. Extend some other pre-defined rules e.g using @extend .btn;
e. Use Operators like addition division, logic etc
f. Add functionalities that allow you to use functions called Mixins