Skip to content

Instantly share code, notes, and snippets.

@hiphopsmurf
hiphopsmurf / secure-auth-cookies.php
Created November 28, 2016 17:03 — forked from tott/secure-auth-cookies.php
Encrypt WordPress auth cookies
<?php
function sav_encrypt_cookie( $decrypted ) {
$encrypted = mcrypt_encrypt( MCRYPT_RIJNDAEL_256, substr( AUTH_SALT, 0, 32 ), $decrypted, MCRYPT_MODE_ECB, mcrypt_create_iv( mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB ), MCRYPT_RAND ) );
return trim( base64_encode( $encrypted ) );
}
function sav_decrypt_cookie( $encrypted ) {
$decrypted = mcrypt_decrypt( MCRYPT_RIJNDAEL_256, substr( AUTH_SALT, 0, 32 ), base64_decode( $encrypted ), MCRYPT_MODE_ECB, mcrypt_create_iv( mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB ), MCRYPT_RAND ) );
return trim( $decrypted );
@hiphopsmurf
hiphopsmurf / gist:c1f18408eb1b4557bb0344cb909cef7a
Last active December 1, 2016 16:38 — forked from fastmover/gist:7771483
Wordpress is lacking an is_subscriber method.
if( !function_exists( "is_subscriber" ) ){
function is_subscriber() {
// Test if role is subscriber
$cu = wp_get_current_user();
if (!empty($cu->roles) && is_array($cu->roles)) {
if(in_array('subscriber', $cu->roles)) {
return true;
}
}
return false;
@hiphopsmurf
hiphopsmurf / Redirect WordPress Logout to Home Page
Last active December 3, 2016 06:38 — forked from bwhli/Redirect WordPress Logout to Home Page
Redirect WordPress Logout to Home Page
//* Redirect WordPress Logout to Home Page - Anonymous Function
add_action('wp_logout',create_function('','wp_redirect(home_url());exit();'));
// Redirect WordPress Logout to Home Page - Full Function
function logout_redirect_home(){
wp_safe_redirect(home_url());
exit;
}
add_action('wp_logout', 'logout_redirect_home');
@hiphopsmurf
hiphopsmurf / replace-wp-dashboard.php
Created January 17, 2017 18:56 — forked from wpscholar/replace-wp-dashboard.php
Replace the default WordPress dashboard with a custom one
<?php
/**
* Plugin Name: Replace WordPress Dashboard
* Description: Replaces the default WordPress dashboard with a custom one.
* Author: Micah Wood
* Author URI: http://micahwood.me
* Version: 0.1
* License: GPL3
*/
@hiphopsmurf
hiphopsmurf / README.md
Created January 18, 2017 17:50 — forked from foosel/README.md
OctoPrint Filetab plugin & configuration instructions

Moving the "Files" component from the sidebar to the tab section

  1. Create .octoprint/plugins/filetab and .octoprint/plugins/filetab/templates
  2. Copy __init__.py to .octoprint/plugins/filetab
  3. Copy filetab_tab.jinja2 to .octoprint/plugins/filetab/templates
  4. Modify .octoprint/plugins/config.yaml to include files in the disabled values for sidebar (see example)
  5. Optional: Adjust the order for tab if you want the "Files" tab to be placed somewhere else than after the regular tab components (see example)
  6. Restart OctoPrint, verify in the log that it discovered the plugin
@hiphopsmurf
hiphopsmurf / luhn.java
Created February 24, 2017 01:33 — forked from mdp/luhn.java
Luhn algorithm (mod10) in Java
/**
* Luhn Class is an implementation of the Luhn algorithm that checks validity of a credit card number.
*
* @author <a href="http://www.chriswareham.demon.co.uk/software/Luhn.java">Chris Wareham</a>
* @version Checks whether a string of digits is a valid credit card number according to the Luhn algorithm. 1. Starting with the second to last digit and
* moving left, double the value of all the alternating digits. For any digits that thus become 10 or more, add their digits together. For example,
* 1111 becomes 2121, while 8763 becomes 7733 (from (1+6)7(1+2)3). 2. Add all these digits together. For example, 1111 becomes 2121, then 2+1+2+1 is
* 6; while 8763 becomes 7733, then 7+7+3+3 is 20. 3. If the total ends in 0 (put another way, if the total modulus 10 is 0), then the number is valid
* according to the Luhn formula, else it is not valid. So, 1111 is not valid (as shown above, it comes out to 6), while 8763 is valid (as shown
* above, it comes ou
@hiphopsmurf
hiphopsmurf / gist:dc1c2bae643819f88e90891ae37203bc
Created March 8, 2017 18:02 — forked from jimkutter/gist:1370525
List of US States in a PHP array
<?php
array(
'AL' => 'Alabama',
'AK' => 'Alaska',
'AZ' => 'Arizona',
'AR' => 'Arkansas',
'CA' => 'California',
'CO' => 'Colorado',
'CT' => 'Connecticut',
@hiphopsmurf
hiphopsmurf / SaveAs-UTF8.py
Created November 5, 2017 00:18 — forked from ptim/SaveAs-UTF8.py
ST3 super simple plugin: Save the current file with encoding UTF8, then close.
import sublime, sublime_plugin
'''
A response to: http://stackoverflow.com/questions/19831757/how-to-create-macro-in-sublime-text-3-with-saveas-and-close-file-command
Save the current file with encoding UTF8, then close.
To trigger the command with 'Command Option Shift 8',
add the following to your Sublime Text > Preferences > Keybindings - User
@hiphopsmurf
hiphopsmurf / jquery.getScript.js
Created November 23, 2017 03:02 — forked from tmilewski/jquery.getScript.js
Replace the normal jQuery getScript function with one that supports debugging and which references the script files as external resources rather than inline. Helps with debugging in IE.
// Helps with IE debugging.
jQuery.extend({
getScript: function(url, callback) {
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
var done = false; // Handle Script loading
script.src = url;
script.onload = script.onreadystatechange = function() { // Attach handlers for all browsers
if ( !done && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") ) {
@hiphopsmurf
hiphopsmurf / README.md
Created November 23, 2017 03:05 — forked from steveosoule/README.md
jQuery.getScript Cached

jquery.getScriptCached.js

jQuery's $.getScript function is a quick and easy way to include external JavaScript files into a website. However, its default implimentation will not cache the script file for the client.

The following information describes how you can itilize cached versions of $.getScript

Usage

  1. Include jquery, if it's not already.