Skip to content

Instantly share code, notes, and snippets.

View pmkhoa's full-sized avatar

Khoa Pham pmkhoa

View GitHub Profile
@pmkhoa
pmkhoa / index.html
Created January 9, 2024 14:38 — forked from CodeMyUI/index.html
LIGHT Flickering Animation (Vanilla CSS)
<div>
<span id="L">L</span>
<span id="I">I</span>
<span id="G">G</span>
<span id="H">H</span>
<span id="T">T</span>
</div>
@pmkhoa
pmkhoa / pQuery.js
Created November 7, 2022 19:12 — forked from niyazpk/pQuery.js
Add or update query string parameter
// Add / Update a key-value pair in the URL query parameters
function updateUrlParameter(uri, key, value) {
// remove the hash part before operating on the uri
var i = uri.indexOf('#');
var hash = i === -1 ? '' : uri.substr(i);
uri = i === -1 ? uri : uri.substr(0, i);
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
@pmkhoa
pmkhoa / spotify-token-app.js
Created March 18, 2022 23:30 — forked from Symbitic/spotify-token-app.js
Example of obtaining a Spotify token
/*
Make sure to download spotify-token-index.html and rename it to public/index.html
Before running this application, make sure to replace CLIENT_ID and CLIENT_SECRET below.
Also, make sure to register http://localhost:8989/ and http://localhost:8989/callback/ as callbacks in your developer console.
THE TRAILING SLASHES ARE IMPORTANT!
Run this with:
deno run -A spotify-token-app.js
*/
@pmkhoa
pmkhoa / app.rb
Created February 8, 2020 01:20
CORS for Sinatra
before do
headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS'
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Headers'] = 'accept, authorization, origin'
end
options '*' do
response.headers['Allow'] = 'HEAD,GET,PUT,DELETE,OPTIONS,POST'
response.headers['Access-Control-Allow-Headers'] = 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Cache-Control, Accept'
@pmkhoa
pmkhoa / wp_usermeta.md
Created December 24, 2019 07:25 — forked from magnific0/wp_usermeta.md
Show and Edit User Meta in Wordpress

#Show and Edit User Meta in Wordpress

Description

This simple procedure will allow you to:

  1. Display user meta fields under in the user list as additional columsn (Users > All Users).
  2. Display these fields on user profiles.
  3. Edit these fields under user edit.

This method works completely without plugins and involves just some functions and hooks in functions.php. Plugins like "User Meta Display" achieve this to some level, but treat custom meta fiedlds completely different from the regular fields. They are shown and edited in seperate environment and fail to show the meta data is a table list. This method integrates custom user meta along with regular user (meta).

@pmkhoa
pmkhoa / App.js
Created July 9, 2018 05:51
Prototype for Next.js Shopify app with Swiper and slide color image detection
import Head from 'next/head'
import style from './style'
const App = (props) => (
<div className={`view view--${props.view ? props.view : 'root'} ${props.isBright ? 'is-bright' : 'is-dark'}`}>
<Head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href='/static/app.css' rel='stylesheet' />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.1.6/css/swiper.min.css" />
</Head>
@pmkhoa
pmkhoa / better-nodejs-require-paths.md
Created June 28, 2018 01:52 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

class Example extends React.Component<
Props,
State,
Snapshot
> {
static getDerivedStateFromProps(
nextProps: Props,
prevState: State
): $Shape<State> | null {
// ...
@pmkhoa
pmkhoa / js-exif-rotate.html
Created March 12, 2018 20:41 — forked from runeb/js-exif-rotate.html
Auto-rotate images locally in the browser by parsing exif data
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input id="file" type="file" accept="image/*" />
<br/>
<h2>As read:</h2>
<img id="placeholder1" width=300/><br/>
<h2>Rotated by exif data:</h2>
<img id="placeholder2" width=300/>
<script>
@pmkhoa
pmkhoa / Install-Mcrypt.md
Created February 19, 2018 06:07 — forked from idleberg/Install-Mcrypt.md
Install Mcrypt on macOS

Setup php-mycrypt on macOS (and versions of Mac OS X)

These steps should have been mentioned in the prerequisites of the Laravel Installation Guide, since I'm surely not the only person trying to get Laravel running on macOS.

Install

Install Mcrypt using Homebrew

# PHP 7