Skip to content

Instantly share code, notes, and snippets.

View gundamew's full-sized avatar
🐢
Stepping forward

Steven Chen gundamew

🐢
Stepping forward
  • Taipei City, Taiwan
View GitHub Profile
@gundamew
gundamew / example.md
Created January 20, 2022 10:43
Installing Obsidian (AppImage) on Ubuntu 20.04

1. Move the AppImage to /opt

$ sudo mkdir -p /opt/Obsidian
$ mv ~/Downloads/Obsidian-0.13.19.AppImage /opt/Obsidian

2. Create the desktop entry

@gundamew
gundamew / checkout-gitlab-merge-request.sh
Created March 6, 2019 04:08
Checkout GitLab merge request locally.
#!/usr/bin/env bash
set -euo pipefail
# Ref:
# * https://stackoverflow.com/a/44992513
# * https://github.com/jwiegley/git-scripts/blob/master/git-pr
test -z $1 && echo "Merge request number required." 1>&2 && exit 1
git fetch ${2:-origin} merge-requests/$1/head:mr-$1 && git checkout mr-$1
@gundamew
gundamew / download.php
Last active June 13, 2022 18:50
Download/Upload files with Guzzle.
<?php
$client = new GuzzleHttp\Client();
// Ref: https://guzzle.readthedocs.io/en/latest/request-options.html#sink-option
$client->request('GET', 'http://example.com', [
'sink' => '/tmp/' . sha1(file_get_contents('https://example.com'))
]);
@gundamew
gundamew / FooLogger.php
Last active April 26, 2022 19:31
Custom Logger for Laravel 5.6. Send messages to Telegram.
<?php
namespace App\Logging;
use DateTimeZone;
use Monolog\Logger;
use App\Logging\TelegramBotHandler;
use Monolog\Formatter\LineFormatter;
class FooLogger
@gundamew
gundamew / star-rating-v1.php
Last active November 1, 2021 08:17
Simple PHP helper functions to generate five-star rating stars.
<?php
/**
* Example: five_star_rating_stars(4.8);
* five_star_rating_stars(
* 4.8,
* '<i class="fas fa-star"></i>',
* '<i class="fas fa-star-half-alt"></i>',
* '<i class="far fa-star"></i>'
* );
@gundamew
gundamew / ntd-coin-changer.php
Last active August 12, 2021 08:06
Get the lowest amount of coins for a given change value.
<?php
function change_make($price, $pay)
{
if ($price === 0 || $pay === 0 || $price > $pay) {
return;
}
$change = $pay - $price;
@gundamew
gundamew / AbstractCalculator.php
Last active January 19, 2021 11:07
A chain of responsibility pattern practice.
<?php
use App\Models\Member;
abstract class AbstractCalculator
{
/** @var self */
private $next = null;
/**
@gundamew
gundamew / Media.php
Created January 19, 2021 10:53
A many-to-many polymorphic relations example of Laravel.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Media extends Model {}
@gundamew
gundamew / example.sh
Created January 19, 2021 10:51
Finding a Linux AMI.
#!/usr/bin/env bash
set -euo pipefail
# Ref: Ref: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/finding-an-ami.html
aws ec2 describe-images \
--owners 099720109477 \
--filters "Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-*" \
"Name=architecture,Values=x86_64" \
"Name=virtualization-type,Values=hvm" \
"Name=root-device-type,Values=ebs"
@gundamew
gundamew / example.php
Created January 19, 2021 10:48
Create a custom role based on an existing role in WordPress.
<?php
if ( ! wp_roles()->is_role( 'my_customer' ) ) {
add_role(
'my_customer',
__( 'My customer' ),
array_merge(
wp_roles()->get_role( 'customer' )->capabilities,
array( 'read_shop_order', 'read_private_shop_orders' )
)