Skip to content

Instantly share code, notes, and snippets.

@5SMNOONMS5
5SMNOONMS5 / Demo.js
Last active November 4, 2021 02:21
Find first match chinese and insert some text before it
function insertBeforeFirstChinese(string, insertedString) {
// cf. https://stackoverflow.com/questions/21109011/javascript-unicode-string-chinese-character-but-no-punctuation
const index = string.split("")
.findIndex(char => /\p{Script=Han}/u.test(char))
if (index > 0) {
string = string.substr(0, index) + insertedString + string.substr(index);
}
@5SMNOONMS5
5SMNOONMS5 / CacheMiddleware.php
Last active September 29, 2021 06:22
CacheMiddleware for laravel version 7
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
// @TIP: Import your CacheService depends on your namespace
use App\Service\Cache\CacheService;
@5SMNOONMS5
5SMNOONMS5 / CacheService.php
Last active September 29, 2021 04:26
CacheService
<?php
namespace App\Service\Cache;
use Illuminate\Support\Facades\Cache;
final class CacheService
{
/**
* Is cache has value by given key and tags
import UIKit
import SnapKit_Sources
import PlaygroundSupport
final class TestView: UIView {
let labelPrimary: UILabel = {
let label = UILabel()
label.font = UIFont.systemFont(ofSize: 25)
label.textColor = .black
@5SMNOONMS5
5SMNOONMS5 / to_lowercase.sh
Last active August 31, 2020 05:28
Change file name to lower case
# Ref: https://stackoverflow.com/questions/7787029/how-do-i-rename-all-files-to-lowercase
for f in *; do mv "$f" "$f.tmp"; mv "$f.tmp" "`echo $f | tr "[:upper:]" "[:lower:]"`"; done
@5SMNOONMS5
5SMNOONMS5 / mysql-docker.sh
Created June 17, 2020 08:33 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@5SMNOONMS5
5SMNOONMS5 / Markdium-Shell.bash
Created February 1, 2020 16:00
Markdium-Laradock 下開發遇到 Authentication plugin ‘caching_sha2_password’ cannot be loaded
# Remove old one
brew cask uninstall sequel-pro
# Install new
brew cask install homebrew/cask-versions/sequel-pro-nightly
@5SMNOONMS5
5SMNOONMS5 / Markdium-Shell.bash
Created February 1, 2020 16:00
Markdium-Laradock 下開發遇到 Authentication plugin ‘caching_sha2_password’ cannot be loaded
# 進入 mysql container,(我的 container 叫 mysql 也許你的不一樣)
docker-compose exec mysql bash
# Login into mysql
mysql -u root -p
# Change encryption of the current user's password
ALTER USER 'yourusername'@'localhost' IDENTIFIED WITH mysql_native_password BY 'youpassword';
protocol CLSPickerViewProtocol {
var title: String { get }
var id: Int { get }
}
final class CLSPickerView<T: LLPickerViewProtocol>: UIPickerView, UIPickerViewDelegate, UIPickerViewDataSource {
var selectHandler: ((T) -> Void)?
var contents: [T] = [] {
@5SMNOONMS5
5SMNOONMS5 / CLSTableView.swift
Last active December 11, 2019 09:44
GenericType TableView, Copy and paste into your playground files
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
/// CLSTableViewConfig for extend, add more tableview properties.
struct CLSTableViewConfig {
var heightForRow: CGFloat?
}