Skip to content

Instantly share code, notes, and snippets.

@rbk
rbk / gist:25ad75179d0a76e45a0295bb4e537eb4
Created October 17, 2016 13:56
Sublime Text Settings
{
"always_show_minimap_viewport": true,
"bold_folder_labels": true,
"caret_extra_bottom": 1,
"caret_extra_top": 1,
"caret_extra_width": 1,
"caret_style": "blink",
"color_scheme": "Packages/Boxy Theme/schemes/Boxy Monokai.tmTheme",
"fade_fold_buttons": false,
"font_face": "hermit",
@rbk
rbk / embed.js
Created September 21, 2016 16:14
Embed code snippet
<script type="text/javascript">
(function(){
var s = document.createElement('script');
s.type = 'text/javascript';
a.async = true;
s.src = '';
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
})();
</script>
function slugify( $str ) {
$new_str = $str;
$new_str = preg_replace('/ /', '-', $new_str);
$new_str = preg_replace('/[^A-Za-z0-9\-]/', '', $new_str);
$new_str = strtolower($new_str);
return $new_str;
}
@rbk
rbk / mailchimp.php
Last active August 31, 2016 20:58
Subscript to Mailchimp list via php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MC TEST</title>
</head>
<body>
<?php
define('CLIENT_ID', '');
@rbk
rbk / super-func.php
Created July 22, 2016 17:47
Get an excerpt if one doesn't exist
<?php
function generate_awesome_excerpt( $id, $character_limit, $ending ) {
if( gettype($character_limit) != 'integer' ) {
$character_limit = 100;
}
$post = get_post($id);
$content = $post->post_content;
@rbk
rbk / backup.sh
Created July 12, 2016 15:27 — forked from bradt/backup.sh
Simple Remote Backups for WordPress
#!/bin/bash
BUCKET_NAME=${1-''}
# Get upload folder path using WP-CLI
# We use --url=http://blah.com in our WP-CLI commands so that we don't get the PHP warning about HTTP_HOSTS
UPLOADS_PATH=$(wp eval '$upload_dir = wp_upload_dir(); echo $upload_dir["basedir"];' --url=http://blah.com 2>&1)
if [[ $UPLOADS_PATH =~ Error ]]
then
@rbk
rbk / functions.php
Last active June 29, 2016 20:16
WordPress - Get all post metadata as a nice object that is easier to work with
<?php
function get_post_meta_object( $id ) {
$object = new stdClass();
$meta = get_post_meta( $id );
foreach( $meta as $key => $value ) {
$object->{$key} = $value[0];
}
@rbk
rbk / general.js
Last active June 29, 2016 19:06
Super Console Log for Chrome
function superConsoleLog( arg ) {
console.time( arg );
console.profile( arg );
console.assert( arg );
console.count( arg );
console.debug( arg );
console.dir( arg );
console.dirxml( arg );
console.error( arg );
console.info( arg );
@rbk
rbk / functions.php
Created June 8, 2016 19:55
Query WordPress and add the metadata to the result.
<?php
/*
*
* Get posts with a standard query
* Include all the meta data in the result
*
*/
function get_posts_with_meta( $args ) {
$query = get_posts($args);
@rbk
rbk / scroll.js
Created June 7, 2016 15:31
Cross browser scroll position
// Calculate scroll position in all IE9+ Firefox, Chrome, and Edge
var scrollTop = 0;
window.addEventListener('scroll', function(e){
scrollTop = document.documentElement.scrollTop || window.scrollY;
});