Skip to content

Instantly share code, notes, and snippets.

View TakesTheBiscuit's full-sized avatar

Paul TakesTheBiscuit

  • United Kingdom
  • 14:37 (UTC +01:00)
View GitHub Profile
@TakesTheBiscuit
TakesTheBiscuit / continuous-servo-arduino-sketch
Created August 21, 2018 21:14
continuous rotation servo clock and anticlock
// TURN CLOCKWISE, WAIT A BIT, THEN GO ANTI CLOCK DEMO ONLY
#include <Servo.h>
#define TURN_TIME 1200
Servo myservo;
void setup() {
myservo.attach(9);
@TakesTheBiscuit
TakesTheBiscuit / sailwinchsketch
Created August 21, 2018 20:31
SAIL WINCH DRIVE SKETCH
// type a number on the serial commands
// zoomkat 10-22-11 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.
String readString;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
@TakesTheBiscuit
TakesTheBiscuit / juggle_balls_2.php
Created March 22, 2018 23:12
Blog example juggling 2
<?php
// balls becomes an INT
$balls = 1;
// truthy check (any INTEGER > 0 will be true)
if ($balls) {
$balls += 1;
}
// truthy check: $balls is an INTEGER at this point
if ($balls) {
$balls = true;
@TakesTheBiscuit
TakesTheBiscuit / juggle_balls_1.php
Last active March 22, 2018 23:09
Blog example of juggling 1
<?php
// balls becomes an INT
$balls = 1;
// truthy check
if ($balls) {
$balls += 1;
}
// outputs: 2
echo $balls;
?>
@TakesTheBiscuit
TakesTheBiscuit / discounter.php
Created March 8, 2018 13:15
Discount, give away the least, percent or fixed whichever is lesser
<?php
$discount_that_was_probably_applied = quick_calc_discount_used(1.21,10,11.99);
print_r($discount_that_was_probably_applied);
function quick_calc_discount_used($fixed = 0, $percent = 0, $sell_price) {
$gave_away = 0;
$method_used = false;
$final_sell = 0;
<?php
$stringage = [
'order_id'=>'5678',
'name'=>'NO ONE cares'
];
echo replace_with_personal_data('There was a problem on order #[order_id] please phone [name]', $stringage);
<?php
$arr = ["7",
"13",
"4",
"5",
"13",
"18",
"28",
"7",
@TakesTheBiscuit
TakesTheBiscuit / reverse_word_search.php
Created February 21, 2018 17:26
Reverse word search when reading direction is LTR
<?php
$wildcard_array = explode(' ', 'Delivered to neighbouring city signed for by github.com/TAKESTHEBISCUIT');
echo '<pre>';
print_r(reverseWildcard($wildcard_array));
echo '</pre>';
function reverseWildcard($wildcard_arr_of_words) {
$working_arr = $wildcard_arr_of_words;
$sentences = [];
if ($wildcard_arr_of_words != false) {
@TakesTheBiscuit
TakesTheBiscuit / send.php
Created February 16, 2018 13:53
Sendgrid Example
<?php
// If you are using Composer (recommended)
require 'vendor/autoload.php';
// If you are not using Composer
// require("path/to/sendgrid-php/sendgrid-php.php");
$from = new \SendGrid\Email("Example User", "test@example.com");
$subject = "Sending with SendGrid is Fun";
$to = new \SendGrid\Email("Example User", "takesthebiscuit@somewherenevereverever.co.uk");
@TakesTheBiscuit
TakesTheBiscuit / property_exists.php
Created February 12, 2018 15:10
PHP property exists check
<?php
$str = json_encode(['test'=>true]);
$obj = json_decode($str);
var_dump($obj);
echo PHP_EOL.'<br>';
$keys = [
'tests',