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 / routes.php
Last active May 12, 2017 15:41
Create table views of all registered routes in Laravel and Lumen
<?php
// FOR LARAVEL
Route::get('route-list', function() {
$routeCollection = Route::getRoutes();
echo "<table style='width:100%'>";
echo "<tr>";
echo "<td width='10%'><h4>HTTP Method</h4></td>";
@rslhdyt
rslhdyt / apply-watermark.php
Last active September 22, 2017 13:14
[Intervention Image] Apply multiple watermark to image
<?php
// .....
$img = Image::make('images/picture.jpg');
$watermark = Image::make('images/watermark.png');
$x = 0;
while ($x < $img->width()) {
@rslhdyt
rslhdyt / variable.go
Created September 27, 2017 03:25
Golang variables
package main
import "fmt"
var taste bool
func main() {
fruit := "banana"
count := 10
@rslhdyt
rslhdyt / LoginProviderController.php
Last active October 2, 2017 02:44
Socialite Callback
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use Auth;
use Illuminate\Http\Request;
use Socialite;
@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;
});
@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
<!-- app/Http/Middleware/AdminAuthenticate.php -->
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class AdminAuthenticate
@rslhdyt
rslhdyt / phpunit.php
Created February 18, 2019 14:33
Get session body from phpunit response
<?php
$response = ...
$this->app['session.store']
@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 / 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