Skip to content

Instantly share code, notes, and snippets.

@markkimsal
markkimsal / app_service_provider_include.php
Created March 28, 2024 13:11
Laravel CSRF Breach mitigation (?)
<?php
function csrf_field()
{
return new HtmlString('<input type="hidden" name="_token" value="'.csrf_token().'" autocomplete="off" data-rand="'.substr(str_shuffle(md5(microtime())), 0, rand(0, 100)).'">');
}
@markkimsal
markkimsal / gist:c9bf2caa7cf86c3f8c22e267faec0510
Created June 10, 2023 15:55
cross compile libSDL2 for macos darwin
install zig
install libobjc
get macosX SDK from hexops.
get SDL2
mkdir build; cd build;
@markkimsal
markkimsal / porting_supercubeslide_to_zig.md
Last active July 3, 2023 12:50
Porting Super Cube Slide to Zig

I've had my eye on Zig for a year or so now as a language I'd like to learn. I don't have much use for compiled languages in my normal day-to-day work, so it's challenging to find time to learn new languages.

I remembered that I have an old Python game, Super Cube Slide, that I haven't been able to get building for Windows and have not had great success porting to Python 3.x. After finding a nice SDL wrapper in Zig (https://github.com/MasterQ32/SDL.zig) I thought I'd give a shot at porting to Zig. Hopefully this should let me redistribute binaries to friends and family much easier than setup.py and friends.

A few things about Zig that I noticed right away. There's not much documentation on managing your allocators, and there's no package management system. Lack of package management system kept me away from Go-lang in the early days. In fact, I ported

@markkimsal
markkimsal / console-concurrent-migrate.php
Last active December 1, 2022 14:39
Concurrent-safe migration for Laravel
<?php
$signature = 'lockingmigrate {--database= : The database connection to use}
{--force : Force the operation to run when in production}
{--path=* : The path(s) to the migrations files to be executed}
{--realpath : Indicate any provided migration file paths are pre-resolved absolute paths}
{--pretend : Dump the SQL queries that would be run}
{--seed : Indicates if the seed task should be re-run}
{--step : Force the migrations to be run so they can be rolled back individually}';
Artisan::command($signature, function ($database=false, $seed=false, $step=false, $pretend=false, $force=false, $path=[]) {
@markkimsal
markkimsal / app.Exception.Handler.php
Created November 13, 2019 13:53
Laravel and JSON-API formatting
<?php
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
@markkimsal
markkimsal / host-mysql.php
Created November 1, 2017 20:05
Yield in Amphp\Mysql under Aerys Host
<?php
define('DB_HOST', 'db.service');
define('DB_USER', 'docker');
define('DB_PASS', 'mysql');
use \Amp\Loop;
use \Amp\Mysql\Pool;
use Aerys\{ Host, Request, Response, Websocket, function root, function router, function websocket };
@markkimsal
markkimsal / gist:49935cc36ede1f56de3ca35f3e85f7e5
Created September 14, 2017 22:35
PDO doesn't close the connection
<?php
$user = 'docker';
$pass = 'mysql';
$dsn = "mysql:host=mariadb;dbname=mysql";
$select = 'SELECT * from time_zone';
$conn=new PDO($dsn,$user,$pass);
$data = $conn->query($select);
foreach($data as $row) {
print_r($row);
}
@markkimsal
markkimsal / responsive-tables.less
Created December 23, 2015 17:19
Responsive table columns css
// Extra small screen / phone
@screen-xs: 480px;
@screen-xs-min: @screen-xs;
// Small screen / tablet / phone horizontal
@screen-sm: 640px;
@screen-sm-min: @screen-sm;
// Medium screen / desktop
@screen-md: 768px;
@markkimsal
markkimsal / gist:5333142aab19eff90af1
Created April 9, 2015 19:10
workflow with callbacks
<?php
namespace PHPWorkflow;
trait EventEmitterTrait {
protected $listeners = [];
public function on($event, callable $listener)
{
if (!isset($this->listeners[$event])) {
$this->listeners[$event] = [];
}
@markkimsal
markkimsal / gist:11369832
Created April 28, 2014 12:04
Python PYZMQ PUSH/PULL buffer
#!/usr/bin/python
import zmq
import time
import collections
ctx = zmq.Context()
pull_socket = ctx.socket(zmq.PULL)
pull_socket.bind('tcp://127.0.0.1:5590')