Skip to content

Instantly share code, notes, and snippets.

View BolajiOlajide's full-sized avatar

Bolaji Olajide BolajiOlajide

View GitHub Profile
@BolajiOlajide
BolajiOlajide / mapDispatch2.js
Created June 21, 2017 18:38
Map Dispatch to Prop using the mapDispatchToProps function call
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 = {
@BolajiOlajide
BolajiOlajide / bindActionCreator.js
Created June 21, 2017 18:49
map Dispatch to props using Bind Action Creators from redux
import React from "react";
import PropTypes from "prop-types";
import {connect} from "react-redux";
import {bindActionCreators} from "redux";
import * as courseActions from "../../actions/courseAction";
class CoursesPage extends React.Component {
constructor(props) {
super(props);
@BolajiOlajide
BolajiOlajide / manage.py
Created June 27, 2017 05:24
Minimal Flask application
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == '__main__':
app.run()
@BolajiOlajide
BolajiOlajide / config.py
Last active June 27, 2017 08:33
Configuration settings for the ToDo List API.
"""
Configuration settings for the ToDo List API.
The definition of the different configuration settings is contained here:
- Development Configuration
- Production Configuration
"""
class Config:
"""
@BolajiOlajide
BolajiOlajide / __init__.py
Last active June 27, 2017 09:17
The app initialization for the ToDoList API is defined here.
"""
Setup an initialization to delay the creation of the application after runtime.
This helps to enable the use of blueprint if we ever want to use it in the future.
"""
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from config import config
@BolajiOlajide
BolajiOlajide / setState.py
Created June 28, 2017 17:46
How to use setState function & reference previous State.
this.setState(prevState => {
if (prevState.usedNumbers.length === 9) {
return {doneStatus: 'Done. Nice!'}
}
});
@BolajiOlajide
BolajiOlajide / testSetup.js
Created July 18, 2017 18:18
Setup React app for testing with JSDOM
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`);
global.document = dom.window.document;
global.window = document.defaultView;
const exposedProperties = ['window', 'navigator', 'document'];
Object.keys(document.defaultView).forEach((property) => {
if (typeof global[property] === 'undefined') {
@BolajiOlajide
BolajiOlajide / saveUrlTOAraay.js
Created July 20, 2017 12:43
Save urls in a string to an array and remove space and commas
const saveUrlToArray = (url) => {
const tempArray = url.split(',');
const urlArray = tempArray.map((arr, index) => {
return arr.trim();
});
return urlArray;
}
saveUrlToArray('hnsdjf, https://google.com, http://facebook.com,http://andela.com');
@BolajiOlajide
BolajiOlajide / posgres_ready.sh
Created July 30, 2017 20:48
A shell script for docker images making use of postgres to make the app wait till postgres is ready
#!/bin/bash
# wait for Postgres to start
function postgres_ready() {
python << END
import sys
import psycopg2
try:
conn = psycopg2.connect(dbname="postgres", user="postgres", password="postgres", host="postgres")
except psycopg2.OperationalError:
@BolajiOlajide
BolajiOlajide / config.py
Created August 10, 2017 04:48
Configuration for TODOList API
"""
Configuration settings for the ToDo List API.
The definition of the different configuration settings is contained here:
- Development Configuration
- Production Configuration
"""
class Config:
"""