Skip to content

Instantly share code, notes, and snippets.

View dotherightthing's full-sized avatar

Dan Smith dotherightthing

  • Do The Right Thing
  • Wellington, New Zealand
View GitHub Profile
@dotherightthing
dotherightthing / sass-lint-disable.md
Last active November 1, 2018 04:22
[Disable Sass-lint] Disable Sass-lint rules using comments #linters #scss
@dotherightthing
dotherightthing / phpcs-disable.md
Last active November 1, 2018 04:22
[Disable PHP Code Sniffer] Disable PHP Code Sniffer rules using comments #linters #php
@dotherightthing
dotherightthing / php-version-remote-url.md
Last active November 1, 2018 09:35
[Get PHP version used by a website] #php #curl #security

Get PHP version used by a website

In web browser

  1. curl -I http://www.websitename.com
  2. Append a PHP string to the URL, to display an image-based easter egg that corresponds to a version of PHP

To disable on server

@dotherightthing
dotherightthing / php-unit-testing-revisited.md
Last active November 1, 2018 10:41
[PHP Unit Testing, revisited] #php #unit-testing #wordpress
@dotherightthing
dotherightthing / jquery-noconflict-mode.md
Last active November 1, 2018 10:47
[Using $ in $.noConflict() mode] Use jQuery's $ shortcut in No-Conflict Mode, by passing it into functions as a local variable #js #jquery

Using $ in $.noConflict() mode

How to use the dollar sign as an alias for the jQuery object

Because the jQuery object is used so often, having a short alias is very useful and the dollar sign is so conventional that when people are looking at jQuery code, they are often looking for this dollar sign as an indicator that the jQuery object is being used.

Now we could use a simple assignment to say $ = jQuery and just leave it at that, but the issue is that we don't know if the dollar sign is being used by some other JavaScript library ... So in order to make sure that the dollar sign doesn't get overridden somewhere along the lines, we need to make the dollar sign a local variable for each function that we write

Source: BuildAModule: How to use the dollar sign as an alias for the jQuery object

@dotherightthing
dotherightthing / embed-oembed.md
Last active November 1, 2018 10:48
[oEmbed] oEmbed provides a JSON representation of a resource to consumers, to allow them to embed it in their own page. #embeds

oEmbed

The resource can be specified as one of the following types:

  • photo - an embeddable image
  • video - an embeddable video
  • link - embeddable information about a URL
  • rich - embeddable HTML, usually using an iframe to provide styled and interactive content
@dotherightthing
dotherightthing / character-encoding-utf-8.md
Last active November 1, 2018 10:48
[UTF-8] Why UTF-8 is great. #utf8 #I18n #unicode

UTF-8

Some great information from UTF-8: The Secret of Character Encoding.

Meta tag

I've used the charset meta tag with a UTF-8 value for a long long time and now it's the default in HTML5.

While this can also be achieved on the server, the meta tag is an easy and human-readable way to instruct the browser to use UTF-8.

@dotherightthing
dotherightthing / php-autoloading-and-namespaces.md
Last active November 1, 2018 10:49
[Autoloading and Namespaces] Namespacing prevents classes from leaking into the global scope. #php #wordpress #dev

Autoloading and Namespaces

composer.json

This object instructs Composer to automatically require PHP files inside src, which use the namespace WPDTRT_Plugin:

"autoload": {
  "psr-4": {
 "DoTheRightThing\WPPlugin\\": "src/"
@dotherightthing
dotherightthing / security-tls-and-ssl.md
Last active November 1, 2018 10:50
[TLS vs SSL] TLS and SSL are protocols that provide data encryption and authentication between applications (e.g. browsers & email clients) and servers. #security #http2 #ssl #tls

TLS (Transport Layer Security) and SSL (Secure Sockets Layer)

Summary

TLS (Transport Layer Security) and SSL (Secure Sockets Layer) are protocols that provide data encryption and authentication between applications and servers in scenarios where that data is being sent across an insecure network, such as checking your email. - SSL versus TLS – What’s the difference?

Key differences

  • A program can initiate a secure connection with a server by Port ('explicit' - SSL), or by Protocol ('implicit' - TLS)
  • A negotiation between the client and the server determines which protocol is used. This is based on which software is installed on each and how each is configured.
@dotherightthing
dotherightthing / php-stack-trace.md
Last active November 1, 2018 10:51
[Generating a Stack Trace in PHP] What called what from where? #php #debugging #wordpress

Generating a Stack Trace

Source: StackOverflow - Print PHP Call Stack

Sample output when called from a WordPress Widget Subclass:

#0 /Volumes/DanBackup/Websites/wp-network/wp-includes/class-wp-widget-factory.php(106): WPDTRT_Widget->__construct()
#1 /Volumes/DanBackup/Websites/wp-network/wp-includes/widgets.php(113): WP_Widget_Factory->register('WPDTRT_Attachme...')
#2 /Volumes/DanBackup/Websites/wpdtrt-attachment-map/wpdtrt-attachment-map.php(202): register_widget('WPDTRT_Attachme...')