Skip to content

Instantly share code, notes, and snippets.

View peter-sharp's full-sized avatar

Peter Sharp peter-sharp

View GitHub Profile
@peter-sharp
peter-sharp / contracts...ChristmasBets.sol
Created December 17, 2021 04:14
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity >= 0.6.0 < 0.9.0;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract ChristmasBets {
function placeBet() public payable {
}
@peter-sharp
peter-sharp / array_columnify.php
Last active November 12, 2018 20:53
converts an array of rows to an array of columns
<?php
/**
* converts an array of rows to an array of columns
* @example
* $items = [
* ['id' => 1, 'colour' => 'red'],
* ['id' => 2, 'colour' => 'orange']
* ];
* array_columnify($items); // ['id' => [1, 2], 'colour' => ['red', 'orange']]
*
@peter-sharp
peter-sharp / array_reduce_by.php
Last active November 12, 2018 20:52
reduces items in given array to values of last item with given column
<?php
/**
* reduces items in given array to values of last item grouped by given column
* @example
* $items = [
* ['animal' => 'rabbit', 'age' => 2],
* ['animal' => 'rabbit', 'age' => 8],
* ['animal' => 'dog', 'age' => 12],
* ['animal' => 'dog', 'age' => 1],
@peter-sharp
peter-sharp / array_group_by.php
Created November 8, 2018 00:19
Groups items by given column
<?php
/**
* groups given items by given column
* @param string $column column to group by
* @param array[object|array] $items items to group
* @return array[object|array] grouped items
*/
function array_group_by($column, $items) {
$grouped = [];
@peter-sharp
peter-sharp / add_fallback_archive_your_post_type_template.php
Created November 6, 2018 23:34
Adds fallback plugin template for WordPress post-type archive page
<?php
namespace YourPlugin;
define(__NAMESPACE__."\PATH", plugin_dir_path( __FILE__ ));
function add_fallback_archive_your_post_type_template($template) {
if(!is_post_type_archive('your_post_type')) return $template;
$themeTemplate = locate_template('archive-your-post-type.php');
@peter-sharp
peter-sharp / filterable-field-types.php
Last active January 15, 2019 01:38
WordPress filtereable field type system
<?php
function register_field_type($type, $options) {
foreach ($options as $key => $value) {
$filter = PRFX.$type.'_field_'.$key;
if(is_callable($value)) {
add_filter($filter, $value, 10, 3);
} else {
add_filter($filter, function() use ($value) { return $value; }, 10, 3);
}
@peter-sharp
peter-sharp / wpAjax.js
Created November 1, 2018 01:34
send ajax request to WordPress wp_ajax (jQuery)
function wpAjax(method, action, params) {
return $.ajax($.extend(true, {
method: method,
url: ajaxUrl,
data: {
action: action
}
}, params));
}
@peter-sharp
peter-sharp / Stylefile.yml
Created July 30, 2018 23:06
Customizations for motoronefinance.dev.webmad.co.nz via StyleURL.
---
version: 1.0
domains:
- motoronefinance.dev.webmad.co.nz
url_patterns:
- motoronefinance.dev.webmad.co.nz/*
timestamp: '2018-07-30T23:06:52Z'
id: 9RfO
redirect_url: http://motoronefinance.dev.webmad.co.nz/?s=loan
shared_via: StyleURL - (https://styleurl.app) import and export CSS changes from Chrome
@peter-sharp
peter-sharp / Stylefile.yml
Created July 30, 2018 22:32
Customizations for policies.webmad.co.nz via StyleURL.
---
version: 1.0
domains:
- policies.webmad.co.nz
url_patterns:
- policies.webmad.co.nz/*
timestamp: '2018-07-30T22:32:09Z'
id: coQF
redirect_url: http://policies.webmad.co.nz/wp-login.php?redirect_to=http%3A%2F%2Fpolicies.webmad.co.nz%2Fwp-admin%2Fpost.php%3Fpost%3D495%26action%3Dedit&reauth=1
shared_via: StyleURL - (https://styleurl.app) import and export CSS changes from Chrome
@peter-sharp
peter-sharp / itty-bitty-site.sh
Created July 9, 2018 21:14
itty.bitty.site generator fixed
#! /usr/bin/env bash
echo -n '<h1>hello world</h1>' | lzma -9 | base64 | printf "https://itty.bitty.site/#%s/%s\n" "Title" "$(cat -)