Skip to content

Instantly share code, notes, and snippets.

View dhanangpratama's full-sized avatar
🏠
Working from home

Dhanang Pratama dhanangpratama

🏠
Working from home
  • Jakarta, Indonesia
View GitHub Profile

Install and Config Supervisor in MacOS

Install

Install Supervisor

brew install supervisor

Deployment

@dhanangpratama
dhanangpratama / PreventBackHistory.php
Last active January 28, 2020 09:48
[Laravel Middleware Prevent Back History] #laravel
<?php
namespace App\Http\Middleware;
use Closure;
class PreventBackHistory
{
/**
* Handle an incoming request.
export function sleep(ms) {
const DEF_DELAY = 1000;
return new Promise(resolve => setTimeout(resolve, ms || DEF_DELAY));
}

Place this code in android/build.gradle

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 27 // <-- match this to your project's compileSdkVersion
                buildToolsVersion '27.0.3' // <-- match this to your project's buildToolsVersion
 }
randomKeyFromObject: function(obj) {
return Object.keys(obj)[Math.floor(Math.random()*Object.keys(obj).length)];
}
function randomString($length = 13)
{
// uniqid gives 13 chars, but you could adjust it to your needs.
if (function_exists("random_bytes")) {
$bytes = random_bytes(ceil($length / 2));
} elseif (function_exists("openssl_random_pseudo_bytes")) {
$bytes = openssl_random_pseudo_bytes(ceil($length / 2));
} else {
throw new Exception("no cryptographically secure random function available");
}
@dhanangpratama
dhanangpratama / how-to.md
Last active January 28, 2020 09:55
[Fixing Error] Error caused by `AAPT: error: resource android:attr/fontVariationSettings not found.` #reactnative

Error caused by:

AAPT: error: resource android:attr/fontVariationSettings not found.

Add below in android/gradle.properties on top of it.

googlePlayServicesVersion=12.0.1

Source: facebook/react-native#25371 (comment)

@dhanangpratama
dhanangpratama / how-to.md
Last active August 1, 2019 17:52
Reverse Proxy Configuration

Don't forget to include /usr/local/etc/nginx/servers folder in /usr/local/etc/nginx/nginx.conf

with syntax: include servers/*;

MacOS location /usr/local/etc/nginx/servers/sub.domain.dv.conf

<?php
$items_per_page = 2;
$page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;
$offset = ( $page * $items_per_page ) - $items_per_page;
$query = 'SELECT * FROM '.$table_name;
$total_query = "SELECT COUNT(1) FROM (${query}) AS combined_table";
$total = $wpdb->get_var( $total_query );
$results = $wpdb->get_results( $query.' ORDER BY id DESC LIMIT '. $offset.', '. $items_per_page, OBJECT );
/*
*
@dhanangpratama
dhanangpratama / wp-get-id-from-image-url.php
Last active January 28, 2020 09:54
[Get the ID from image URL] #wordpress
<?php
function get_image_id_from_url($image_url)
{
global $wpdb;
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ));
return $attachment[0];
}