Skip to content

Instantly share code, notes, and snippets.

Avatar
💣
'); DROP TABLE statuses; --

Ian Littman iansltx

💣
'); DROP TABLE statuses; --
View GitHub Profile
@iansltx
iansltx / booster.php
Created November 28, 2022 05:11
Post Booster
View booster.php
<?php
// The script will keep its place based on a file called min_id, which should contain
// the ID of the post after which we should start boosting. If we don't specify an ID,
// we'll grab the latest 40 posts and boost them, writing the min_id file as we go
// through the list. So if you don't want to potentially duplicate boosts, make sure
// a status ID is in that file.
// To run this script, you'll need to install PHP. You can do that on an Ubuntu 22.04 box by running
// sudo apt install php-cli
@iansltx
iansltx / 2020-08-23 17:44.txt
Created August 23, 2020 22:44
Nighthawk M1 Austin AT&T Field Test
View 2020-08-23 17:44.txt
ian@fiora:~/Desktop/platform-tools$ telnet 192.168.1.1 5510
Trying 192.168.1.1...
Connected to 192.168.1.1.
Escape character is '^]'.
AT!GSTATUS?
AT!GSTATUS?
!GSTATUS:
Current Time: 1035 Mode: ONLINE
System mode: LTE PS state: Attached
EMM state: Registered Normal Service
@iansltx
iansltx / property-bench.php
Created April 10, 2020 21:19
Microbenchmark for typed property vs. setter
View property-bench.php
<?php
// Compares the performance of a trivial typehinted setter with a public typed property
define('ITERATIONS', 1_000_000);
ini_set('memory_limit', '384M');
$arrays = [];
echo "Building data...";
@iansltx
iansltx / Container.php
Last active September 12, 2019 22:46
Dependency Injection Sample Code - 2019
View Container.php
<?php
class Container implements Psr\Container\ContainerInterface {
protected $s = [];
function __set($k, $c) { $this->s[$k]=$c; }
function __get($k) { return $this->s[$k]($this); }
function get($k) { return $this->s[$k]($this); }
function has($k) { return isset($s[$k]); }
}
@iansltx
iansltx / UuidModel.php
Created August 1, 2019 20:49
UUID Model
View UuidModel.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Ramsey\Uuid\Uuid;
// Abstract class using inheritance rather than composition to avoid trait override errors
abstract class UuidModel extends Model
{
View ModifyExistingEnum.php
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class ModifyExistingEnum extends Migration
{
public function up()
{
View More optimized load test result
/\ |‾‾| /‾‾/ /‾/
/\ / \ | |_/ / / /
/ \/ \ | | / ‾‾\
/ \ | |‾\ \ | (_) |
/ __________ \ |__| \__\ \___/ .io
execution: local
output: influxdb=http://influxdb:8086/k6 (http://influxdb:8086)
script: /scripts/base.js
View getLines.php
<?php // works on single-file non-ZIp64 zip files compressed with deflate (AKA a common case), licensed MIT
function getLinesFromZippedCSVfromURL(string $url) : \Generator
{
$stream = fopen($url, 'rb');
fread($stream, 4 + 2 + 2 + 2 + 2 + 2 + 4); // skip up to compressed size
// bindec() was doing weird things, hence converting through hex first
// sttrev() to match endian-ness to expectations; zip file values are little-endian
@iansltx
iansltx / talks.php
Created April 30, 2019 18:09
List of everyone who has submitted Joind.in talk comments for a given event
View talks.php
<?php
$eventId = 7021;
#$eventId = 7045; #Yorkshire, for testing
$comments = json_decode(file_get_contents('https://api.joind.in/v2.1/events/'.$eventId.'/talk_comments?resultsperpage=9999'), true)['comments'];
$users = [];
foreach ($comments as $comment) {
@iansltx
iansltx / With.php
Created February 27, 2019 07:24
Simulating Python's With keyword with foreach and a trait in PHP
View With.php
<?php // Pretty sure this doesn't clean up on exceptions, so keep that in mind
trait With
{
abstract protected function enter(...$args);
protected function exit($built, ...$initArgs)
{
// override this if needed
}