Skip to content

Instantly share code, notes, and snippets.

View jacobwise's full-sized avatar

Jacob Wise jacobwise

View GitHub Profile
var decrypt = function (encrypted, method, secret, hmac) {
var iv = new Buffer.from(encrypted.substr(0, 24), "base64").toString();
var decryptor = crypto.createDecipheriv(method, secret, iv);
return (
decryptor.update(encrypted.substr(24), "base64", "utf8") +
decryptor.final("utf8")
);
};
var tests = 1000;
var i = 0;
var t0 = performance.now();
while (i < tests) {
functionOne()
i++;
}
var t1 = performance.now();
console.log("Call to test 1 took " + (t1 - t0) + " milliseconds.");
@jacobwise
jacobwise / sample-controller.php
Created October 16, 2017 17:55
A sample controller for a WP_Query
<?php
function prefix_get_post_type () {
$args = array(
'post_type' => 'post_type',
'posts_per_page' => 10
);
// The Query
$the_query = new WP_Query( $args );
// Create empty posts array
$posts = array();
@jacobwise
jacobwise / check-originial-username.js
Created November 12, 2015 19:53
Checks if input has illegal characters. I was using it to see if the user already had a valid username.
hasOriginalUsername: function() {
var illegalChars = new RegExp(/\W/); // allow letters, numbers, and underscores
if ( illegalChars.test( this.originalUsername ) ) {
return true;
} else{
@jacobwise
jacobwise / override_user_login.php
Last active November 12, 2015 19:16
Override user_login in WordPress
// Check if user_login already exists before we force update
if ( ! username_exists( $username ) ) {
// Force update user_login and user_nicename
$tablename = $wpdb->prefix . "users";
$wpdb->update( $tablename, // Table to Update ( prefix_users )
array(
'user_login' => $username, // Data to Update ( user_login )
'user_nicename' => $username // Data to Update ( user_nicename )
),
@jacobwise
jacobwise / get_recent_posts.php
Last active August 29, 2015 14:27
Gets the 4 most recent WordPress posts on the forum.
<?php
$url = 'https://luminous-landscape.com/wp-json/posts?filter[posts_per_page]=4';
get_recent_posts( $url );
function get_recent_posts( $url ) {
$json = file_get_contents($url);
@jacobwise
jacobwise / MemberMapper.php
Last active August 29, 2015 14:26
Class to retrieve JSON and add posts to WordPress Database
<?php namespace Plugin\Models;
use Plugin\Helper;
class MemberMapper
{
public function sync_members( $post_id )
{
$admins = get_users( array( 'role' => 'administrator', 'fields' => 'ID' ) );
@jacobwise
jacobwise / remove-entry-header-genesis
Created April 30, 2015 15:15
Remove Entry Header Genesis on front page
<?php
add_action( 'genesis_before', 'prefix_remove_entry_header' );
/**
* Remove Entry Header
*/
function prefix_remove_entry_header()
{
if ( ! is_front_page() ) { return; }
@jacobwise
jacobwise / .gitignore
Created April 17, 2015 13:40
Starter .gitignore
*~
.DS_Store
.svn
.cvs
*.bak
*.swp
Thumbs.db
# wordpress specific
wp-config.php
/**
* Add and extra class to the entry-content div
*
*/
function jw_entry_content_class( $attributes ) {
if ( is_tax( $taxonomy ) )
$attributes['class'] .= $class_to_add;
return $attributes;