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 / 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' )
)
@gundamew
gundamew / example.php
Created January 19, 2021 10:45
Adopted Google API client library with Laravel.
<?php
use Illuminate\Support\Carbon;
use Google_Client;
use Google_Service_Sheets;
use Google_Service_Sheets_Request;
use Google_Service_Sheets_ValueRange;
use Google_Service_Sheets_BatchUpdateSpreadsheetRequest;
class Example
@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 / OrderPermissions.php
Created January 19, 2021 10:39
A Laravel native RBAC example. Try to do it myself.
<?php
namespace App\Permissions;
class OrderPermissions
{
const VIEW = 'view_order';
const VIEW_ANY = 'view_any_orders';
const CREATE = 'create_order';
const UPDATE = 'update_order';