Skip to content

Instantly share code, notes, and snippets.

@haipham
haipham / tailwind-colors-as-css-variables.md
Created January 8, 2024 02:21 — forked from Merott/tailwind-colors-as-css-variables.md
Expose Tailwind colors as CSS custom properties (variables)

This is a simple Tailwind plugin to expose all of Tailwind's colors, including any custom ones, as custom css properties on the :root element.

There are a couple of main reasons this is helpful:

  • You can reference all of Tailwind's colors—including any custom ones you define—from handwritten CSS code.
  • You can define all of your colors within the Tailwind configuration, and access the final values programmatically, which isn't possible if you did it the other way around: referencing custom CSS variables (defined in CSS code) from your Tailwind config.

See the Tailwind Plugins for more info on plugins.

@haipham
haipham / acf-slider.php
Created December 20, 2023 03:54 — forked from FernE97/acf-slider.php
PHP: WordPress - Advanced Custom Fields Slider
<?php if ( get_field( 'slides' ) ) : // repeater field ?>
<ul class="slider">
<?php while ( the_repeater_field( 'slides' ) ) :
$image = get_sub_field( 'slide' ); // sub-field image ID
$slide = wp_get_attachment_image_src( $image, 'slides' );
$alt = get_post_meta( $image, '_wp_attachment_image_alt', true );
?>
<li><img src="<?php echo $slide[0]; ?>" alt="<?php echo $alt; ?>"></li>
<?php endwhile; ?>
@haipham
haipham / concurrent-pool.php
Created November 1, 2023 13:08 — forked from tonysm/concurrent-pool.php
Concurrent Requests
<?php
// 1. Register the routes
Route::get('test/{lorem}', function ($lorem) {
sleep(3);
return response()->json([
'message' => $lorem,
'token' => Str::random(),
]);
@haipham
haipham / WhoisRegexDataGetter.php
Created September 25, 2023 16:28 — forked from pentagonal/WhoisRegexDataGetter.php
Get Detail Data From Whois Domain Result (#PCRE REGULAR EXPRESSION)
<?php
// result data
$resultString = 'Fill With Whois Result';
// Domain .be fixer
$resultString = str_replace("\r", "", $resultString);
if (strpos($resultString, ":\n\t")) {
$arr = explode("\n", $resultString);
$currentKey = null;
foreach ($arr as $key => $value) {
@haipham
haipham / duplicate.vim
Created August 30, 2022 08:26 — forked from AndrewRadev/duplicate.vim
Duplicate lines and blocks of code in Vim
" Pressing zj and zk duplicate a single line below and above the cursor,
" respectively. This is pretty common functionality and simple to implement.
"
" Pressing zJ and zK duplicates a "block" of code, which is defined by indent.
" In the languages from the s:indent_based_languages list, a "hanging" indent
" is taken. Example:
"
" def one(self):
" pass
"
@haipham
haipham / S3.php
Created August 8, 2022 06:03 — forked from marcoarment/S3.php
A simple PHP class to perform basic operations against Amazon S3 and compatible services.
<?php
/*
A simple PHP class to perform basic operations against Amazon S3 and compatible
services. Requires modern PHP (7+, probably) with curl, dom, and iconv modules.
Copyright 2022 Marco Arment. Released under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
@haipham
haipham / sticky-focus.js
Created May 17, 2022 13:11 — forked from enwin/sticky-focus.js
Detect and change the scroll position when a focused element is under a sticky element
// sticky element
var stickyHeader = document.querySelector( '.intro-banner' );
function handleFocus( e ){
// don't try to change the scroll if the focused element is in the sticky element
if( stickyHeader.contains( e.target )){
return;
}
// quick & dirty client height on each focus
@haipham
haipham / OnClickListenter.md
Created October 26, 2021 19:06 — forked from vxhviet/OnClickListenter.md
setOnclickListener vs OnClickListener vs View.OnClickListener

Source: StackOverflow

Personal Note: Prefer method 2 as Big Nerd Ranch's Android Programming also use this method.

Imagine that we have 3 buttons for example

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
@haipham
haipham / AppServiceProvider.php
Created July 22, 2021 03:38 — forked from simonhamp/AppServiceProvider.php
A pageable Collection implementation for Laravel
<?php
namespace App\Providers;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
class AppServiceProvider extends ServiceProvider
{
public function boot()
@haipham
haipham / LaravelRecursiveBlade.php
Created July 19, 2021 05:39 — forked from Lemmings19/LaravelRecursiveBlade.php
How to create a recursive list in a Blade. (Laravel)
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class TestController extends Controller
{
/**
* This is just a quick example of how to create a recursive list of items