Skip to content

Instantly share code, notes, and snippets.

jaswrks jaswrks

View GitHub Profile
jaswrks / flush-dns-script.bash
Created Jul 5, 2018
Bash script intended for macOS that flushes DNS cache and also flushes Chrome's host cache and socket pool automatically.
View flush-dns-script.bash
#!/usr/bin/env bash
# Flush DNS cache.
sudo dscacheutil -flushcache;
sudo killall -HUP mDNSResponder;
# Clear Chrome's DNS cache.
osascript <<EOD
tell application "Google Chrome"
tell front window
jaswrks / delete_all_data.php
Created Jul 3, 2018
protected function delete_all_data()
View delete_all_data.php
* Deletes all data.
protected function delete_all_data() : void {
global $wpdb;
foreach ( [
View .gitattributes
# Text/Binary ---
# Default
* text=auto
# Text
*.md text
*.txt text
jaswrks / .gitignore
Last active Apr 16, 2018
View .gitignore
# Ignore ---------------------------------------------------------------------------------------------------------------
# Local
# Logs
View strict-mode.bash
#!/usr/bin/env bash
# Strict mode.
set -o nounset;
set -o errexit;
set -o errtrace;
set -o pipefail;
# Shell options.
jaswrks /
Created Mar 21, 2018
Fun Facts about Alaska

Fun Facts About Alaska 🏔

  • Alaska is a really big place, check this.
  • More than half the world’s glaciers can be found Alaska.
  • There are 3 million lakes in Alaska and more than 3,000 rivers.
  • Only 700k people live here (approx. one person per square mile).
  • In contrast, there are 175k moose in Alaska. We see them everywhere.
  • Alaska contains about 98% of the total U.S. brown bear population and 70% of the total North American population. There are 30k brown bears here. That's in addition to 100k black bears and about 4,500 polar bears.
  • We have earthquakes on a daily basis. Each year Alaska has about 5,000 earthquakes including 1,000 that measure above 3.5 on the Richter scale. Of these, I feel an average of about one earthquake each week.
  • Alaska is the only U.S. state name you can type on one row of a keyboard.
jaswrks / wp-config-ngrok.php
Last active Mar 5, 2018
View wp-config-ngrok.php
&& stripos( $_SERVER['HTTP_X_FORWARDED_PROTO'], 'https' ) !== false ) {
$_SERVER['HTTPS'] = 'on';
jaswrks /
Last active Feb 14, 2018
Type Declarations

Type Declarations

Type Declarations aren't required, nor are they appropriate in all cases. However, type declarations do make code more readable. They also protect code, because type declarations are a way of enforcing data types in the parameters passed to a function. For example, you can force callers to pass an array, or a specific type of object, such as a WP_REST_Request. If a caller doesn't pass the data type expected, PHP throws a recoverable fatal error or exception. This is advantageous because type declarations produce improved error messages that catch problems right away.

When are type declarations appropriate?

When you're writing a function or class method that expects to receive an array or a specific object type, and there is no reason to accept anything other than that specific data type.

protected function foo( Bar $bar, array $items ) {
View is_content_empty.php
* Checks if comment content is empty.
* @param string $content Content to check.
* @return bool True if empty or not a string.
function is_content_empty( $content ) {
if ( ! is_string( $content ) ) {
jaswrks /
Created Jan 22, 2018 — forked from Gozala/
Range hilighting code using getClientRects API

Highlight Selection Ranges

Code here takes a DOM Selection Range instance and creates a highlighting for it by using getClientRects. Approach was inspired by marks although here function attempts to find nearest positioned parent element to the commonAncestorContainer and draw all the highilighting rectangles there, this avoids issues with an overflowing content.


  • Approach ignores z-index which isn't great as some element might be overlaying the selection in which case it should not appear, but it does if we use high z-index value. If we use low z-index value then some elements (possibly ones containing selection) might end up overlaying selection itself.
  • Rendered selections are scattered all o
You can’t perform that action at this time.