Skip to content

Instantly share code, notes, and snippets.

View carestad's full-sized avatar
🤗

Alexander Karlstad carestad

🤗
View GitHub Profile
@carestad
carestad / gist:3842750
Created October 5, 2012 22:12
MySQL 5.X UTF-8 config
[client]
character-set-server = utf8
[mysqld]
character-set-server = utf8
collation-server = utf8_unicode_ci
character-sets-dir = /usr/share/mysql/charsets
#default-character-set = utf8
init-connect = 'SET NAMES utf8'
@carestad
carestad / cssversioner.php
Created October 5, 2012 19:56 — forked from vidluther/cssversioner.php
Add a query string to the end of the theme's style.css when WordPress is loaded.
<?php
/**
* Add a filter to stylesheet_uri, which appends a query string to it automagically.
*/
add_filter('stylesheet_uri', function($css) {
$parts = parse_url($css);
$file = $_SERVER['DOCUMENT_ROOT'] . $parts['path'];
@carestad
carestad / skyss.sh
Last active April 4, 2017 20:14
Skyss travel planner [Bash style]
#!/bin/bash
#
# By: Alexander Karlstad <alexanderkarlstad@gmail.com>
#
# Requires 'jq' and 'curl'
#
# To install (on Ubuntu):
# sudo apt install jq curl
function halp() {
@carestad
carestad / .bash_completion.jotta
Created April 23, 2018 17:43
Bash completion for jotta-cli
#!/bin/bash
function _jottacli() {
local config_params cmds cur first params prev second
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
first=${COMP_WORDS[1]}
second=${COMP_WORDS[2]}
prev=${COMP_WORDS[COMP_CWORD-1]}
@carestad
carestad / convert-first-page-pdf-to-jpg.php
Created February 22, 2019 11:54
Convert first page of PDF to JPG thumbnail in PHP
<?php
$file = '/foo/bar/document.pdf';
$im = new \Imagick($file);
$im->setIteratorIndex(0); // just use first page
$im->setImageAlphaChannel(\Imagick::VIRTUALPIXELMETHOD_WHITE); // Other alpha options are available, see Imagick PHP documentation
$im->setImageColorspace(\Imagick::COLORSPACE_SRGB); // Other colorspaces are available, see Imagick PHP documentation
$im->setImageBackgroundColor('white'); // Set transparent background elements to this color
$im->setFormat('JPG'); // Format, a wide variety is supported

Keybase proof

I hereby claim:

  • I am carestad on github.
  • I am karlstad (https://keybase.io/karlstad) on keybase.
  • I have a public key ASBdjb4nFyklP4MvxzxDntz8_HIN-VFz1SKRfFHtBqUJbAo

To claim this, I am signing this object:

@carestad
carestad / apt-slack.sh
Last active July 17, 2019 07:59
Script to notify on Slack when updates are available in APT. Logs already reported packages on a $0.log file.
#!/bin/bash
#
# Author: Alexander Karlstad <carestad@github>
# Updated: 2019-07-17
# Configurable variables
slack_channel="@alexander"
slack_icon=":information_source:"
slack_user="apt@$(hostname -f)"
slack_webhook=""
@carestad
carestad / DataUriToFile.php
Last active November 6, 2019 12:09
Middleware to detect if a POST parameter of a given type is present, and if it is a data URI string we convert it to an instance of UploadedFile and make it accessible via Laravel's Request class and the file handling methods there.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\UploadedFile;
class DataUriToFile
{
/**
@carestad
carestad / FooRequest.php
Last active December 8, 2020 18:16
[Laravel] Return validation errors as proper object/arrays
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class FooRequest extends FormRequest
{
public function authorize()
{
@carestad
carestad / Timestamp.php
Last active May 26, 2021 08:15
Doctrine DBAL Timestamp type for use with Laravel
<?php
namespace Database\Migrations\Types;
use DateTime;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\PhpDateTimeMappingType;
use Doctrine\DBAL\Types\Type;