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
@v1vendi
v1vendi / api_generator.js
Created August 20, 2019 19:19
REST API functional generator
const fetch = (...args) => console.log(...args) // mock
function httpRequest(url, method, data) {
const init = { method }
switch (method) {
case 'GET':
if (data) url = `${url}?${new URLSearchParams(data)}`
break
case 'POST':
case 'PUT':
case 'PATCH':
@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">
<?php
global $post;
$author_id=$post->post_author;
?>
<?php
/* You can also use one of these instead:
- nickname
- user_nicename
- display_name
@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
@olivierlacan
olivierlacan / migrate_postgresql_database.md
Last active March 24, 2022 20:30
How to migrate a Homebrew-installed PostgreSQL database to a new major version (9.3 to 9.4) on OS X. See upgraded version of this guide: http://olivierlacan.com/posts/migrating-homebrew-postgres-to-a-new-version/

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:

@mudge
mudge / test.retry.php
Created July 8, 2013 13:27
A retry function for PHP.
<?php
require_once dirname(__FILE__) . '/../lib/simpletest/autorun.php';
function retry($f, $delay = 10, $retries = 3)
{
try {
return $f();
} catch (Exception $e) {
if ($retries > 0) {
sleep($delay);