Skip to content

Instantly share code, notes, and snippets.

View rslhdyt's full-sized avatar
🎯
Focusing

Risal Hidayat rslhdyt

🎯
Focusing
View GitHub Profile
@rslhdyt
rslhdyt / Customer.php
Created April 29, 2019 03:30
[Searchable Traits] Simple searchable traits for laravel model #laravel #search #simpleSearch #traits
<?php
namespace App\Models;
use App\Models\Traits\Searchable;
use Illuminate\Database\Eloquent\Model;
class Customer extends Model
{
use Searchable;
@rslhdyt
rslhdyt / DepositTest.php
Created April 20, 2019 16:41
[Mock Koperasi Api Request] example mocking koperasi io request #mocking #phpunit #laravel
<?php
...
/**
* A basic test example.
*
* @return void
*/
public function testSearchPageResult()
@rslhdyt
rslhdyt / FormGroupInput.vue
Created March 16, 2019 06:11
[Form Group Component] Vuejs form group component wrapper using bootstrap-vue and vee-validate #vuejs #validation #bootstrap
<template>
<ValidationProvider :rules="rules" :name="$attrs.label">
<b-form-group slot-scope="{ valid, errors }" :label="$attrs.label" :invalid-feedback="errors[0]">
<b-input
:state="errors[0] ? false : (valid ? true : null)"
:name="$attrs.label.toLowerCase()"
:type="$attrs.type"
:placeholder="$attrs.placeholder"
v-model="innerValue" />
</b-form-group>
@rslhdyt
rslhdyt / test_rspec.rb
Last active March 11, 2019 10:19
Rspec Race Conditions
describe 'Race condition POST /api/v1/transaction/electricity', vcr: { cassette_name: 'race_condition_transaction_electricity' } do
it { expect(ActiveRecord::Base.connection.pool.size).to eq(5) }
context 'send requests simultaneously' do
let!(:user) { create(:user, limit_credit: 500_000, balance: 60_000) }
it 'should create one transaction' do
begin
concurrency_level = 4
fail_occurred = false
@rslhdyt
rslhdyt / App.vue
Last active November 30, 2019 06:25
[watch nested data] vue js watch nested data #vuejs #javascript #vuewatch
<script>
export default {
data: () => ({
form: {
id: 1
text: 'ABC'
}
}),
watch:{
'form.id': function (newVal, oldVal){
@rslhdyt
rslhdyt / UserController.php
Last active February 23, 2019 04:29
Custom Pagination URL laravel
<?php
class UserController extends Controller
{
public function index()
{
$users = App\Models\Member::paginate(15, ['*'], "page[limit]");
$users->appends(['name' => 'bertho']);
@rslhdyt
rslhdyt / phpunit.php
Created February 18, 2019 14:33
Get session body from phpunit response
<?php
$response = ...
$this->app['session.store']
<!-- app/Http/Middleware/AdminAuthenticate.php -->
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class AdminAuthenticate
@rslhdyt
rslhdyt / .htpasswd
Created April 13, 2018 17:54
Basic Auth Nginx configuration
# create encrypted password
# sudo sh -c "echo -n 'fpp:' >> /etc/nginx/.htpasswd"
# sudo sh -c "openssl passwd bar >> /etc/nginx/.htpasswd"
foo:BKlWoa/TUkUgc
@rslhdyt
rslhdyt / ProductController.php
Last active March 1, 2018 03:05
Laravel : overide paginate collection object
<?php
....
$products = Product::paginate();
$products->getCollection()->each(function($product) {
// insert new data
$product->price = 1000;
});