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
@flattened_array = [] #To store the flattened array
def flatten(array)
array.each do |value|
# If value is itself an array, call the function recursively
# Store each value found that is not array in the flattened array
value.instance_of? Array ? flatten value : @flattened_array << value
end
@flattened_array
end
<?php
global $post;
$author_id=$post->post_author;
?>
<?php
/* You can also use one of these instead:
- nickname
- user_nicename
- display_name
@bosunolanrewaju
bosunolanrewaju / caesar.rb
Created November 3, 2016 15:19 — forked from matugm/caesar.rb
Caesar cipher using Ruby
ALPHABET_SIZE = 26
def caesar_cipher(string)
shiftyArray = []
charLine = string.chars.map(&:ord)
shift = 1
ALPHABET_SIZE.times do |shift|
shiftyArray << charLine.map do |c|
((c + shift) < 123 ? (c + shift) : (c + shift) - 26).chr
@bosunolanrewaju
bosunolanrewaju / test.retry.php
Last active May 9, 2022 17:21 — forked from mudge/test.retry.php
A retry function for PHP.
<?php
require_once dirname(__FILE__) . '/../lib/simpletest/autorun.php';
// Retries $f (A function) with arguments ($args as array)
// 3 ($retries) times after 10 secs $delay
// Usage:
// retry( 'function_name', array('arg1', 'arg2'), 15, 5 );
// #=> Retries function_name 5 times with arg1 and $arg2 as arguments at interval of 15 secs
function retry($f, $args = null, $delay = 10, $retries = 3)
{
@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?
@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 / 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 / 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 / README.md
Created March 20, 2018 10:41 — forked from hofmannsven/README.md
My simply MySQL Command Line Cheatsheet
@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