Skip to content

Instantly share code, notes, and snippets.

@thepsion5
thepsion5 / script.js
Created Jul 10, 2020
Tampermonkey Script to hide the "Trending Now" sidebar on Twitter
View script.js
// ==UserScript==
// @name Trending Now No More
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Removes the Trending Now section on Twitter
// @author Sean Mumford
// @match https://twitter.com/*
// @grant none
// ==/UserScript==
@thepsion5
thepsion5 / bootstrap.php
Created Jan 13, 2020
Example of Autoloading In a Legacy PHP Application
View bootstrap.php
<?php
//FILE LOCATION: project-directory/config/bootstrap.php
declare(strict_types=1);
//Composer autoloader file
require_once __DIR__ . '/../vendor/autoload.php';
error_reporting(E_ALL | E_NOTICE);
//Load the files required for configuration
$configuration = require __DIR__ . '/settings.php';
$countyList = require __DIR__ . '/../vendor/some-other-package/list-of-tennessee-counties.php';
@thepsion5
thepsion5 / example_query.php
Created Dec 19, 2019
Example solution for a question posted in a PHP Facebook group
View example_query.php
<?php
/*
The question:
if ( $date_text == 'Sunday' ){
$sql = "update table set sun = $date where "id ='$_REQUEST[num]";
$sql1= "update table set sun = $date where "id ='$_REQUEST[num1]";
mysql_query($con,$sql);
mysql_query($con,$sql1);
}
@thepsion5
thepsion5 / User.php
Last active Aug 23, 2019
Example of a PHP class that stores dynamic properties in an array
View User.php
<?php
/**
* Example of a PHP class that stores dynamic properties in an array, and then can be used to create a SQL statement
*
* I would consider this a proof-of-concept and I do not believe this is a good practice
*/
class User
{
/**
* @var array Object attributes
@thepsion5
thepsion5 / TwitterProfileTest.php
Created Sep 28, 2018
Example of a unit test for an implementation of a Twitter Profile PHP class taken from a project at work, using PHPUnit
View TwitterProfileTest.php
<?php
namespace App\Tests\Domain\Twitter;
use App\Domain\Twitter\TwitterProfile;
class TwitterProfileTest extends \App\Tests\BaseUnitTest
{
private $accessToken = 'oauth-token';
private $accessSecret = 'oauth-secret';
@thepsion5
thepsion5 / pagination.php
Created Sep 3, 2018
A simple example of procedural PHP code that can be used to generated paginated results from a database query
View pagination.php
<?php
require 'setup/connection.php'; //returns a PDO instance;
$searchTerm = isset($_GET['search']) ? $_GET['search'] : null;
$currentPage = isset($_GET['page']) ? $_GET['page'] : 1;
//Step 1: Get the total number of results for a search
$sqlParams = [];
$totalResultSql = 'SELECT COUNT(*) AS count FROM articles ';
if ($searchTerm) {
$sqlParams['search'] = "%$searchTerm%";
@thepsion5
thepsion5 / Application.php
Created Jun 28, 2018
Example of a Small PHP Application Built Without A Framework
View Application.php
<?php
//FILENAME: /spaghetti-monster/src/Application.php
namespace SpaghettiMonster;
use SpaghettiMonster\Domain\EntityRepository;
use SpaghettiMonster\Domain\EntitySearch;
use SpaghettiMonster\Domain\EntityUpdater;
use SpaghettiMonster\Domain\Twitter\ApiClient;
use SpaghettiMonster\Domain\Twitter\TweetCreator;
@thepsion5
thepsion5 / legacy-app-index.php
Created Oct 13, 2017
An example of how an external package containing pure domain logic can be cleanly integrated into different applications
View legacy-app-index.php
<?php
//FILE: legacy-application/public/index.php
require_once __DIR__ . '/../vendor/autoload.php';
$config = require __DIR__ . '../config/settings.php';
$counties = require __DIR__ . '/../vendor/my-company/my-package/src/counties.php';
$app = \App\Application::createFromConfig($config, $counties);
@thepsion5
thepsion5 / GeneratesPermutationsTrait.php
Last active Aug 31, 2017
Example Permutation Generation
View GeneratesPermutationsTrait.php
<?php
trait GeneratesPermutationsTrait
{
/**
* Generates an array with N unique combinations of inputs and a unique output, where N is equal to 2^count($params)
* For example, generatePermutations([], 'Param 1', 'Param 2') would return something similar to:
* [
* [
* 'inputs' => ['Param 1v1', 'Param 2v1'],
@thepsion5
thepsion5 / whyyyyyyyy.php
Created May 16, 2017
Did you know you can shove entire chunks of HTML into a PHP array key? WELL YOU CAN
View whyyyyyyyy.php
<?php
//Formatting and indentation unchanged from original file
$find = $_GET['find'];
$browse = $_GET['browse'];
//More awful code ommitted to preserve the sanity of readers
if(isset($find)) {
$find = addcslashes(mysql_real_escape_string($find), "%_");
$rs = new MySQLPagedResultSet("SELECT * FROM TableName WHERE MATCH (Name) AGAINST ('$find' IN BOOLEAN MODE) ORDER BY Name ASC", 100, $dbConnect);
}
You can’t perform that action at this time.