Skip to content

Instantly share code, notes, and snippets.

View forkbombe's full-sized avatar
🎯
Focusing

Joe Buckle forkbombe

🎯
Focusing
View GitHub Profile
@forkbombe
forkbombe / twitterWidget.class.php
Created August 9, 2014 10:36
A WordPress Twitter Widget Class
<?php
class twitterWidget extends WP_Widget {
public function config() {
return 'twitterWidget'; // Obj
}
function __construct() {
parent::__construct(
'twitter_widget', // Base ID
@forkbombe
forkbombe / sorting-example.js
Last active August 29, 2015 14:16
Example of sorting numbers in a weight-based order
var items = function(num) {
var arr = [1,3,3,5,2,7,4,10,6,4];
/*
* Sort array low-high first
*/
arr.sort(function(a,b) {
return a - b;
});
@forkbombe
forkbombe / backupdb.sh
Created September 1, 2015 07:54
Automated backup of MySQL database via cron
#!/bin/sh
USER=$1
PASS=$2
DB=$3
HOST=''
DATE=`date +"%Y%m%d"`
cd ~/db-daily
mysqldump -u $USER -p$PASS -h $HOST $DB | gzip > $DB.sql.gz
@forkbombe
forkbombe / monit.py
Created July 21, 2016 15:43
Python Consol Args Example using psutil
#!/usr/bin/env python
import sys
import getopt
import psutil
def main(argv):
# Define variables
cpuout = False
@forkbombe
forkbombe / install.sh
Created July 26, 2016 12:45
A basic bash install executable script
#!/bin/bash
cd /tmp
## Get the executable
wget https://path/to/bin
## Make home for command
mkdir ~/bin
## Copy executable to command directory
cp /tmp/[bin] ~/bin/[command]
@forkbombe
forkbombe / modal-object.js
Created August 24, 2016 13:54
Re-usable modal using jquery-ui plus extension for WordPress AJAX
/**
* Example init
*
* new Modal('login-form', {
* title = 'Please Log In',
* content = preloader.spawn();
* });
*
* @param name
* @param options
@forkbombe
forkbombe / @import.regex
Created November 17, 2016 15:26
Regex - find all lines starting with @import and ending with ;
/([@import]*)(@import+)(.*;)(\r?\n|$)/g
@forkbombe
forkbombe / dealCards.php
Created October 3, 2018 09:49
I was asked in a job interview to deal 5 random playing cards to n number of players
<?php
class Deck {
protected $suits = array('Hearts', 'Spades', 'Clubs', 'Diamonds');
protected $ranks = array('Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King');
public function cards() {
$cards = [];
foreach($this->suits as $suit) {
foreach($this->ranks as $rank) {
$cards[] = $rank . " of " . $suit;
@forkbombe
forkbombe / countWords.php
Last active October 3, 2018 09:51
I was asked in a job interview to count all words in a string ignoring capitals and special characters
<?php
$str = "About nine o'clock the moon was sufficiently bright for me to proceed on my way and I had no difficulty in following the trail at a fast walk, and in some places at a brisk trot until, about midnight, I reached the water hole where Powell had expected to camp. I came upon the spot unexpectedly, finding it entirely deserted, with no signs of having been recently occupied as a camp.
I was interested to note that the tracks of the pursuing horsemen, for such I was now convinced they must be, continued after Powell with only a brief stop at the hole for water; and always at the same rate of speed as his.
I was positive now that the trailers were Apaches and that they wished to capture Powell alive for the fiendish pleasure of the torture, so I urged my horse onward at a most dan1gerous pace, hoping against hope that I would catch up with the red rascals before they attacked him.
Further speculation was suddenly cut short by the faint report of two shots far ahead of me. I knew that Powell would need
@forkbombe
forkbombe / listener.php
Last active October 3, 2018 12:34
Create WordPress action hooks for Stripe Hooks
<?php
class Stripe_Hook {
public function __construct() {
$this->listener();
}
public function listener() {
if (isset($_GET['wps-listener']) && $_GET['wps-listener'] == 'stripe') {