Skip to content

Instantly share code, notes, and snippets.

View jasonyost's full-sized avatar

Jason Yost jasonyost

View GitHub Profile
@jasonyost
jasonyost / wp_admin_user.sql
Created April 28, 2018 20:28
Create WP Admin User via MySQL
INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`)
VALUES ('newadmin', MD5('pass123'), 'firstname lastname', 'email@example.com', '0');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, (Select max(id) FROM wp_users), 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, (Select max(id) FROM wp_users), 'wp_user_level', '10');
@jasonyost
jasonyost / letteravatar.js
Created November 8, 2016 20:47 — forked from vctrfrnndz/letteravatar.js
Generate SVG letter avatar
function drawCircle(text, size, color) {
var textSize = Math.ceil(size / 2.5);
var font = 'Proxima Nova, proxima-nova, HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif';
var colors = ["#1abc9c", "#16a085", "#f1c40f", "#f39c12", "#2ecc71", "#27ae60", "#e67e22", "#d35400", "#3498db", "#2980b9", "#e74c3c", "#c0392b", "#9b59b6", "#8e44ad", "#bdc3c7", "#34495e", "#2c3e50", "#95a5a6", "#7f8c8d", "#ec87bf", "#d870ad", "#f69785", "#9ba37e", "#b49255", "#b49255", "#a94136"];
var colorIndex = Math.floor((text.charCodeAt(0) - 65) % colors.length);
var finalColor = color || colors[colorIndex];
var template = [
'<svg height="' + size + '" width="' + size + '" style="background: ' + finalColor + '">',
'<text text-anchor="middle" x="50%" y="50%" dy="0.35em" fill="white" font-size="' + textSize + '" font-family="' + font + '">' + text.toUpperCase() + '</text>',
@jasonyost
jasonyost / rspec_rails_cheetsheet.rb
Last active October 8, 2016 03:57 — forked from them0nk/rspec_rails_cheetsheet.rb
Rspec Rails cheatsheet (include capybara matchers)
#Model
expect(@user).to have(1).error_on(:username) # Checks whether there is an error in username
expect(@user.errors[:username]).to include("can't be blank") # check for the error message
#Rendering
expect(response).to render_template(:index)
#Redirecting
@jasonyost
jasonyost / exclude_categories.php
Created June 30, 2016 23:00
Exclude categories from categories widget in WordPress
// Add to functions.php in the theme to exclude categories from the built-in categories widget
function exclude_widget_categories($args){
$exclude = "105,102,108,112"; // The IDs of the excluding categories
$args["exclude"] = $exclude;
return $args;
}
add_filter("widget_categories_args","exclude_widget_categories");
@jasonyost
jasonyost / arr_flatten.rb
Last active July 22, 2016 02:13
Flatten a nested array
module ArrFlatten
# Public: Returns a flat array
#
# nested_array - A nested array
#
# Examples
# nested_array = [ [1,2,3], [4,5,6], [7,8,9] ]
# ArrFlatten.arr_flatten(nested_array)
# => [1, 2, 3, 4, 5, 6, 7, 8, 9]
#
@jasonyost
jasonyost / keepfocus.js
Created March 22, 2016 23:54
Keep focus on a field
$('<element>').on('blur',function () { var blurEl = $(this); setTimeout(function() {blurEl.focus()},10) });
@jasonyost
jasonyost / explode.rb
Created February 3, 2015 21:24
Ruby explode string into chracter array
"Hello, world!".split(//)
#=> ["H", "e", "l", "l", "o", ",", " ", "w", "o", "r", "l", "d", "!"]
@jasonyost
jasonyost / mixednumregex.rb
Last active August 29, 2015 14:14
Regex to find mixed number in string
/^(\d++(?! *\/))? *-? *((?:(\d+) *\/ *(\d+)))?(.*)$/
# "1 1/2 parts".scan(/^(\d++(?! *\/))? *-? *((?:(\d+) *\/ *(\d+)))?(.*)$/) => [["1", "1/2", "1", "2", " parts"]]
# "25ml".scan(/^(\d++(?! *\/))? *-? *((?:(\d+) *\/ *(\d+)))?(.*)$/) => [["25", nil, nil, nil, "ml"]]
# "1 ounce".scan(/^(\d++(?! *\/))? *-? *((?:(\d+) *\/ *(\d+)))?(.*)$/) => => [["1", nil, nil, nil, "ounce"]]
@jasonyost
jasonyost / jquery.smooth-scroll.coffee
Created December 19, 2014 02:17
jQuery Smooth Scroll
$("a[href*=#]:not([href=#])").click ->
if location.pathname.replace(/^\//, "") is @pathname.replace(/^\//, "") or location.hostname is @hostname
target = $(@hash)
target = (if target.length then target else $("[name=" + @hash.slice(1) + "]"))
if target.length
$("html,body").animate
scrollTop: target.offset().top
, 1000
false
@jasonyost
jasonyost / bak.sh
Created September 27, 2014 01:12
bash/zsh quick file backup and diff
#Make a quick backup of a file before changing it:
cp /path/to/your-file{,.bak}
#Make some changes, then compare the newly-edited file and its backup:
diff /path/to/your-file{.bak,}
#Undo changes: