Skip to content

Instantly share code, notes, and snippets.

View qutek's full-sized avatar
💻
Working from home

Lafif Astahdziq qutek

💻
Working from home
View GitHub Profile
@qutek
qutek / .bash_profile
Created April 16, 2019 18:25
[Custom cd function] Custom bash function to cd in my local server directory with autocomplete
# Use it with `goto project`
goto () {
# cancel if no arguments
if [ -z "$1" ]; then
echo "Mau goto kemana??"
return 0
fi
local UPPER=$(printf "%s" "$1" | tr '[:lower:]' '[:upper:]');
local P_DIR="/Users/qutek/LocalServer/_$UPPER";
@qutek
qutek / readme.md
Created February 21, 2019 22:01
[Move MySQL Data] Move mysql data to another machine

Move mysql to another machine

Old Server

  • Stop mysql server
  • Copy contents of datadir to another location on disk (~/mysqldata/*)
  • Start mysql server again (downtime was 10-15 minutes)
  • compress the data (tar -czvf mysqldata.tar.gz ~/mysqldata)
  • copy the compressed file to new server

New Server

@qutek
qutek / command.md
Created February 21, 2019 21:15
[Disable Mission Control] Disable mission control / spaces on drag to top of screen #mac

Disable:

defaults write com.apple.dock mcx-expose-disabled -bool TRUE && killall Dock

Enable:

defaults delete com.apple.dock mcx-expose-disabled && killall Dock

@qutek
qutek / force-login.php
Last active March 28, 2020 21:16
[ Force Login ] Force login WordPress user without password, use it as plugin or place the code under mu-plugins / wp-config.php ( after `require_once(ABSPATH . 'wp-settings.php');` )
<?php
/**
* Auto login user without password, access with <code>http://domain.com/?force_login=username</code>
* [email protected]
*/
if ( ! defined( 'WP_CLI' ) ) {
function force_login() {
if( !isset($_GET[ 'force_login' ]) || empty( $_GET[ 'force_login' ] ) )
return;
@qutek
qutek / instruction.md
Last active November 7, 2023 12:45
[Install ZeroMQ MAC] Install PHP ZeroMQ MAC #mac #php

Install with brew

  • brew install zmq

Make php-zmq

  • git clone git://github.com/mkoppanen/php-zmq.git
  • cd php-zmq
  • phpize && ./configure
  • make && make install

Add extension to php.ini:

@qutek
qutek / debug-email.php
Last active March 14, 2018 07:31
[Debug Email] Simple script to change all email recipients for debugging / development purpose #wordpress #email #development-tools
<?php
/**
* Plugin Name: Debug Email
* Description: Simple script to change all email recipients for debugging / development purpose
* Version: 0.1
* Author: Lafif Astahdziq
* Author URI: https://lafif.me
*/
add_action( 'init', 'test_send_email' );
@qutek
qutek / calculateStripeFee.js
Created February 3, 2018 06:20
[Calculate Stripe Fee] Calculate stripe fee to ask customer to cover stripe fee #javascript #stripe
/**
* Calculate stripe fee from amount
* so you can charge stripe fee to customers
* lafif <[email protected]>
*/
var fees = {
USD: { Percent: 2.9, Fixed: 0.30 },
GBP: { Percent: 2.4, Fixed: 0.20 },
EUR: { Percent: 2.4, Fixed: 0.24 },
CAD: { Percent: 2.9, Fixed: 0.30 },
@qutek
qutek / o2a.php
Created December 29, 2017 03:21
[PHP Convert multidimensional object to array] #php #array
<?php
/**
* Convert object to array
* @param [type] $obj [description]
* @return [type] [description]
*/
function obj_to_array($obj) {
if(!is_array($obj) && !is_object($obj))
return $obj;
@qutek
qutek / question-1.php
Last active October 9, 2017 11:24
WP Quiz
<?php
/**
* Question #1
* Scenario:
* 1. We have a list of companies in the Company custom post type.
* 2. Each Company has a ranking which is stored in post meta with a key called `ranking. The ranking is a decimal value between 0 and 100. A sample `ranking` is 94.9.
* 3. Each Company can also be marked as sponsored. If a Company is sponsored, a post meta with a key called `sponsored` is updated to 1. Otherwise, the `sponsored` meta value is `0` for each Company.
*
* Problem:
* Given the above scenario, provide the correct array of $args to pass into a new WP_Query instance so that we can return 100 companies with the "sponsored" companies first, and then after that sorted, from highest to lowest based off the `ranking` value.
@qutek
qutek / generate_ssl.md
Last active November 22, 2023 00:49
[Server][MacOs] Generate local SSL with SAN (Subject Alternative Name), works with Chrome 5.8+

Generate local SSL with SAN

Since version 58, Chrome requires SSL certificates to use SAN (Subject Alternative Name) instead of the popular Common Name (CN), thus CN support has been removed.

To create SSL with SAN, use steps as follows

  • Go to your target ssl directory (mine was /usr/local/etc/httpd/ssl)
  • Create .conf file
  • Generate SSL
  • Point the cert on your apache conf