Skip to content

Instantly share code, notes, and snippets.

View bosunolanrewaju's full-sized avatar
😅
Dancing in the Rain

'Bosun Olanrewaju bosunolanrewaju

😅
Dancing in the Rain
View GitHub Profile
@bosunolanrewaju
bosunolanrewaju / app.js
Created April 19, 2020 17:03
List pending migrations in Node.js using Sequelize ORM (similar to Rails)
// call this in your app entry file
// Prints:
// ==================================================
// ABORT: You have pending migrations
// ==================================================
// 1. 20200419162657-create_site_settings.js
//
// Please run `yarn migrate` to run all pending migrations
export const checkPendingMigrations = () => {
@bosunolanrewaju
bosunolanrewaju / override_wp_user_query.php
Last active June 6, 2021 20:09
How to remove the slow SQL_CALC_FOUND_ROWS from WP_User_Query and replace with standard COUNT() which is more performant.
<?php
/**
* Before sql query is generated, intercept `query_vars` and set `count_total` to false
* to prevent `SQL_CALC_FOUND_ROWS` from being added to the sql query.
* Also set our new `query_vars` attribute to true to track if count is required.
*/
add_action( 'pre_get_users', function($wpq) {
if ( isset($wpq->query_vars['count_total'] ) && $wpq->query_vars['count_total'] ) {
$wpq->query_vars['count_total'] = false;
$wpq->query_vars['run_count'] = true;
@bosunolanrewaju
bosunolanrewaju / my.cnf
Created June 28, 2018 09:18
Enable binlog for mysql
#Enabling binlog inside mysql configuration file
log-bin=bin.log
log-bin-index=bin-log.index
max_binlog_size=100M
binlog_format=row
socket=mysql.sock
@bosunolanrewaju
bosunolanrewaju / gist:6a90e57faba7e75d719ba1871b57faaa
Created April 5, 2018 09:53 — forked from giannisp/gist:ebaca117ac9e44231421f04e7796d5ca
Upgrade PostgreSQL 9.6.5 to 10.0 using Homebrew (macOS)
After automatically updating Postgres to 10.0 via Homebrew, the pg_ctl start command didn't work.
The error was "The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.0."
Database files have to be updated before starting the server, here are the steps that had to be followed:
# need to have both 9.6.x and latest 10.0 installed, and keep 10.0 as default
brew unlink postgresql
brew install postgresql@9.6
brew unlink postgresql@9.6
brew link postgresql
@bosunolanrewaju
bosunolanrewaju / aws-go+docker-setup.sh
Created March 29, 2018 14:49 — forked from 0sc/aws-go+docker-setup.sh
Setup script for golang, docker and docker-compose on Amazon Linux AMI 2017.09.0 (HVM) on EC2
#!bin/sh
# Update installed packages and package cache
sudo yum update -y
# make sure in the home folder
cd ~/
# Golang installation
@bosunolanrewaju
bosunolanrewaju / README.md
Created March 20, 2018 10:41 — forked from hofmannsven/README.md
My simply MySQL Command Line Cheatsheet
@bosunolanrewaju
bosunolanrewaju / node-on-ec2-port-80.md
Created September 11, 2017 11:12 — forked from kentbrew/node-on-ec2-port-80.md
How I Got Node.js Talking on EC2's Port 80

The Problem

Standard practices say no non-root process gets to talk to the Internet on a port less than 1024. How, then, could I get Node talking on port 80 on EC2? (I wanted it to go as fast as possible and use the smallest possible share of my teeny tiny little micro-instance's resources, so proxying through nginx or Apache seemed suboptimal.)

The temptingly easy but ultimately wrong solution:

Alter the port the script talks to from 8000 to 80:

}).listen(80);
@bosunolanrewaju
bosunolanrewaju / migrate_postgresql_database.md
Created May 11, 2017 20:35 — forked from olivierlacan/migrate_postgresql_database.md
How to migrate a Homebrew-installed PostgreSQL database to a new major version (9.3 to 9.4) on OS X

This guide assumes that you recently run brew upgrade postgresql and discovered to your dismay that you accidentally bumped from one major version to another: say 9.3.x to 9.4.x. Yes, that is a major version bump in PG land.

First let's check something.

brew info postgresql

The top of what gets printed as a result is the most important:

@bosunolanrewaju
bosunolanrewaju / shipping-calculator.php
Created March 26, 2017 10:25
Code snippet for adding Local governments select field to WooCommerce cart shipping calculator
<?php if ( class_exists( 'WC_All_Country_Counties' ) &&
in_array(
'all-countries-counties-for-wc/all-countries-counties-for-wc.php',
apply_filters( 'active_plugins', get_option( 'active_plugins' ) )
) ) :
$current_lga = WC()->customer->local_government;
?>
<p class="form-row form-row-wide" id="calc_shipping_local_government_field">
@bosunolanrewaju
bosunolanrewaju / included_resource_param.rb
Last active December 14, 2016 14:32
Building nested array of hash(es) from strings separated with dots
class IncludedResourceParams
require 'facets'
attr_reader :include_param
def initialize(include_param)
@include_param = include_param
end
def has_included_resources?