Skip to content

Instantly share code, notes, and snippets.

View ratiw's full-sized avatar

Rati Wannapanop ratiw

  • Nonthaburi, Thailand
View GitHub Profile
@ratiw
ratiw / gist:2d9b0b625c25e0db348713323a11f90d
Created April 14, 2024 14:15
HeidiSQL Connecting via SSH Tunnel
https://www.heidisql.com/forum.php?t=24073
@ratiw
ratiw / RunningNumberGenerator.php
Last active April 25, 2022 10:53
Make new running number (e.g. doc no., invoice no.) based on the given pattern and the last number.
<?php
namespace App\Services;
class InvalidPatternException extends \Exception
{
}
/**
* Pattern is enclosed in the open and close delimiter
@ratiw
ratiw / Bahttext.php
Last active July 19, 2021 09:31
convert number to thai baht text
<?php
/**
* Convert number amount to Thai text as in Excel
*
* author: Rati Wannapanop
* email: rati.wannapanop@gmail.com
* since: 2014-09-06
*/

Steps

  1. Setup Laravel app
  2. Setup vue.js inside laravel app

Setup Laravel app

  • New Laravel app
  • Rename .env.example to .env
  • Config config/database.php to MySQL or SQLite
  • For SQLite, run touch storage/database.sqlite to create sqlite database
@ratiw
ratiw / install-laravel-project.sh
Created October 10, 2020 03:20 — forked from cse031sust02/install-laravel-project.sh
Bash Script to install Laravel project from Git on LEMP stack
#!/bin/sh
########################################################
# Bash script to install HeavyGari Laravel App
# Written by Talha Ibne Imam
########################################################
HC='\033[0;32m' # Heading Color
WC='\033[0;33m' # Warning Color
NC='\033[0m' # No Color
@ratiw
ratiw / Laravel Homestead on Windows.md
Last active February 13, 2020 11:18
#Laravel #Homestead on #Windows

Problem with VirtualBox 4.3.12

It seems there is some problems between Vagrant 1.6.2 and VirtualBox 4.3.12 (the latest at the time or writing this), switching back to VirutalBox 4.3.6 or VirtualBox 4.3.8 seems to eliminate the problem.

update 1: Try both Vagrant 1.6.2 and VirtualBox 4.3.12 on Mac and they seem to work fine!

update 2: You need to enable Virtual Machine option in your BIOS to make VirtualBox work as expected. Saw someone mention about this in Laravel forum about this and it is true.

Also, Vagrant version should be 1.6.2.

@ratiw
ratiw / extract_vars.js
Last active January 22, 2020 17:56
JS function to extract variables from template string
function extract_vars(template, openChar, closeChar) {
openChar = openChar || '{';
closeChar = closeChar || '}';
var i = 0;
var data = [];
do {
if (template[i] == '{') {
for (var j=i+1; j<template.length; j++) {
@ratiw
ratiw / Set DB_CONNECTION to use sqlite in-memory database when testing.md
Last active January 1, 2020 05:24
Set DB_CONNECTION to use sqlite in-memory database when testing

#Set DB_CONNECTION to use sqlite in-memory database when testing

  • Open `phpunit.xml' file in the current project
  • Add the following environment variables to the appropriate section
  <env name="DB_CONNECTION" value="sqlite">
  <env name="DB_DATABASE" value=":memory:">
  • in config\database.php file, change the default sqlite connection to
  'connections' => [
@ratiw
ratiw / object_get.js
Last active May 15, 2019 22:14
Retrieve object property using dot notation. Equivalent to Laravel's object_get()
function object_get(obj, key) {
if (!key || $.trim(key) == '') return obj;
$.each(key.split('.'), function(idx, seg) {
if (typeof obj !== 'object' || obj[seg] === undefined) {
obj = undefined;
return obj;
}
obj = obj[seg];
});
return obj;