Skip to content

Instantly share code, notes, and snippets.

View TakesTheBiscuit's full-sized avatar

Paul TakesTheBiscuit

View GitHub Profile
@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;
@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 / 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 / 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 / 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 / toolhead home position sketch
Created August 21, 2018 22:10
monitoring digital pins continuously
void setup() {
//start serial connection
Serial.begin(9600);
//configure pin 2 as an input and enable the internal pull-up resistor
pinMode(2, INPUT_PULLUP);
pinMode(13, OUTPUT);
}
void loop() {
@TakesTheBiscuit
TakesTheBiscuit / continuous-servo-until-limit-arduino
Last active December 3, 2022 09:18
Continuous servo until limit switch arduino
#include <Servo.h>
#define TURN_TIME 1200
Servo toolheadServo;
int toolheadHome = 0;
boolean toolheadGoingHome = false;
int discContact = 0;
@TakesTheBiscuit
TakesTheBiscuit / open_and_close_cd_tray.py
Last active January 2, 2024 16:52 — forked from rvzzz/open_and_close_cd_tray.py
Open and close CD/DVD Tray in python with Windows fix specific drive letter
#!/usr/bin/python3
from platform import system as platform_name
from os import system
import ctypes
platforms_dictionary = {
"Windows": { #
"open" : 'ctypes.windll.WINMM.mciSendStringW(u"open L: type CDAudio alias L_drive", None, 0, None); ctypes.windll.WINMM.mciSendStringW(u"set L_drive door open", None, 0, None)',
"close": 'ctypes.windll.WINMM.mciSendStringW(u"open L: type CDAudio alias L_drive", None, 0, None); ctypes.windll.WINMM.mciSendStringW(u"set L_drive door closed", None, 0, None)'
@TakesTheBiscuit
TakesTheBiscuit / PythonBants.py
Created October 22, 2018 21:49
Python example of a class, picture a terrible version of GTA - yeah, this isn't it
class PoliceMan:
def __init__(self, health, attack, speed):
self.health = health
self.attack = attack
self.speed = speed
self.name = 'PoliceManDEPT101'
# slow fat one has 100 hp, 10 attack, and moves at 25 speed
SlowFatOne = PoliceMan(100.00,10.00,25.00)
@TakesTheBiscuit
TakesTheBiscuit / run_me.php
Created March 18, 2019 20:52
PHP Copy when locked out of wordpress
<?php
// i cant remember where wp-plugins live, lets assume we want everything from the level above?
$output = shell_exec('scp -r ../ [email protected]:/some/remote/directory/bar');
// Display the scp output
echo "<pre>$output</pre>";
?>