Skip to content

Instantly share code, notes, and snippets.

View gander's full-sized avatar
🏠
It’s Not a Bug, It’s a Feature.

Adam Gąsowski gander

🏠
It’s Not a Bug, It’s a Feature.
View GitHub Profile
@gander
gander / query-collection-snippet.php
Last active November 5, 2021 09:58
Laravel when Closure $callback snippets
<?php
$callback = function () {
};
collect()->when($callback, static function (\Illuminate\Support\Collection $collection, \Closure $callback) {
return \Illuminate\Support\Collection::wrap($callback($collection));
}); // Same as \DB::query()->get(), Model::query()->get()
\DB::query()->when($callback, static function (\Illuminate\Database\Query\Builder $query, \Closure $callback) {
@gander
gander / github-watch-releases.ts
Created December 2, 2020 23:33
Use playwright to enable release notifications in all starred repositories
import {chromium as browser, ElementHandle, Page} from "playwright";
import {default as PQueue} from "p-queue"
const username: string = 'gander'
const links = new Set;
let nextPage: string = '';
(async () => {
const pages = new PQueue({concurrency: 7})
C:\Windows\System32\DisplaySwitch.exe /internal
C:\Windows\System32\DisplaySwitch.exe /external
@gander
gander / shortcuts.md
Last active July 30, 2020 16:33
JetBrains Tips and Tricks
@gander
gander / AutoLinkerForGistCSV.js
Last active December 2, 2020 07:33
convert text into links in table cells
jQuery(() =>
jQuery('td').filter(function() {
return jQuery(this).text().match(/^https?:\/\/.+/);
}).each(function() {
const $this = jQuery(this);
$this.html(jQuery('<a>', {
href: $this.text(),
rel: 'noopener noreferrer',
target: '_blank'
}).text($this.text()));
@gander
gander / TerribleDateFixer.php
Last active December 3, 2020 11:59
Scary code showing how not to code. Found in production
<?php
class DateFixer {
public function fix(string $date): string {
$time = new DateTime($date);
$time->modify('+3 days');
return $time->format('Y-m-d');
}
}