Skip to content

Instantly share code, notes, and snippets.

@zawyelwin
zawyelwin / example.md
Last active December 15, 2020 20:20
Rename all files in a directory based on the line number from a txt file.

Original File name

1.mp4 2.mp4 3.mp4 4.mp4

title.txt

1-abc
2-def
3-ghi
######################################################################### SERVER
resource "azuread_application" "server" {
name = "k8s_server"
reply_urls = ["http://k8s_server"]
type = "webapp/api"
# this is important, as stated by the documentation
group_membership_claims = "All"
required_resource_access {
@zawyelwin
zawyelwin / certificate-renewal.sh
Last active December 1, 2020 07:58
Some handy kubectl commands to make your life easier.Collected from some great resources I found out and some tweaks from their implementations. All credits goes to the original authors.
$ cd /etc/kubernetes/pki/
$ mv {apiserver.crt,apiserver-etcd-client.key,apiserver-kubelet-client.crt,front-proxy-ca.crt,front-proxy-client.crt,front-proxy-client.key,front-proxy-ca.key,apiserver-kubelet-client.key,apiserver.key,apiserver-etcd-client.crt} ~/certs-bak
$ kubeadm init phase certs all
$ cd /etc/kubernetes/
$ mv {admin.conf,controller-manager.conf,kubelet.conf,scheduler.conf} ~/certs-bak
$ kubeadm init phase kubeconfig all
$ reboot
@zawyelwin
zawyelwin / test.yml
Last active September 3, 2020 18:41
A Simple YAML flatten script with dot notation.
en:
questions:
new: 'New Question'
other:
recent: 'Recent'
old: 'Old'
@zawyelwin
zawyelwin / README.md
Created June 21, 2020 18:43 — forked from ColCh/README.md
Create merge request on Gitlab in command line for current branch

Gitlab merge request script

Creates merge request on Gitlab for you

Installation

Download it, add executable perms and place into PATH:

# Place it into ~/.bin
mkdir ~/.bin
@zawyelwin
zawyelwin / Laravel-Container.md
Created May 8, 2020 04:27
Laravel's Dependency Injection Container in Depth

Laravel's Dependency Injection Container in Depth

Translations: Korean (by Yongwoo Lee)

Laravel has a powerful Inversion of Control (IoC) / Dependency Injection (DI) Container. Unfortunately the official documentation doesn't cover all of the available functionality, so I decided to experiment with it and document it for myself. The following is based on Laravel 5.4.26 - other versions may vary.

Introduction to Dependency Injection

I won't attempt to explain the principles behind DI / IoC here - if you're not familiar with them you might want to read What is Dependency Injection? by Fabien Potencier (creator of the Symfony framework).

<?php
function Slug($string){
return strtolower(trim(preg_replace('~[^0-9a-z]+~i', '-', html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', htmlentities($string, ENT_QUOTES, 'UTF-8')), ENT_QUOTES, 'UTF-8')), '-'));
}
$user = 'Cómo hablar en sílabas';
echo Slug($user); // como-hablar-en-silabas
$user = 'Álix Ãxel';
for ns in $(kubectl get ns --no-headers | awk '{print $1}');
do for deploy in $(kubectl -n $ns get deploy --no-headers --ignore-not-found | awk '{print $1}');
do kubectl -n $ns scale deploy $deploy --replicas=1; done;
done;
@zawyelwin
zawyelwin / Example.php
Created April 5, 2020 10:52
Laravel Dynamic Filters from Laracasts Forum series
<?php
namespace App\Filters;
use App\User;
class ThreadFilters extends Filters
{
/**
* Registered filters to operate upon.
@zawyelwin
zawyelwin / VueForms.js
Last active April 5, 2020 10:42
Vue Form Component From Laracasts Vue 2 Series.
class Errors {
/**
* Create a new Errors instance.
*/
constructor() {
this.errors = {};
}
/**