Skip to content

Instantly share code, notes, and snippets.

@obj63mc
obj63mc / clearcloudfiles.rb
Created November 15, 2017 16:38
Ruby script to delete all cloud files and containers - aka shutting down an account. Needs gems 'fog' and 'mime-types'
#!/usr/bin/env ruby
require 'fog'
def delete_file(container, file_num, max_tries)
max_retries ||= max_tries
try = 0
puts "(#{file_num} of #{container.files.count}) Removing #{container.files[file_num].key}"
begin
container.files[file_num].destroy
@obj63mc
obj63mc / migrate_wp.sql
Created November 15, 2017 16:37
Migrate a WordPress Database
update wp_options set option_value = replace(option_value,'old_url','new_url');
update wp_posts set post_content = replace(post_content,'old_url','new_url');
update wp_posts set guid = replace(guid,'old_url','new_url');
update wp_postmeta set meta_value = replace(meta_value,'old_url','new_url');
@obj63mc
obj63mc / pp-timebucket-agg.md
Created November 15, 2017 16:37
PostPogo aggregations via timebuckets -

To aggregate timeseries based off of post types, need two values -

  1. the timebucket wrapper
  2. the type of time series you want (days, minutes, weeks, etc...)

Below gives me aggregation for Feb. 2015 by type by minute -

db.post.aggregate( 
  {$match: {timebucket: "2015-1-m"}}, 

{$unwind: "$timebucket"},

@obj63mc
obj63mc / MongoDB-Vote-Aggregation.md
Created November 15, 2017 16:37
Aggregating Votes on mongodb collection

#Schema

{
  _id:....
  votes:[...]
}

#Aggregation

db.posts.aggregate( [

@obj63mc
obj63mc / varnish-clear-cache
Created November 15, 2017 16:37
Varnish 3 - clear cache
sudo varnishadm "ban req.url ~ ."
@obj63mc
obj63mc / averageRGB.js
Created November 15, 2017 16:36
Calculate average RGB of image using canvas
function getAverageRGB(imgEl) {
var blockSize = 5, // only visit every 5 pixels
defaultRGB = {r:0,g:0,b:0}, // for non-supporting envs
canvas = document.createElement('canvas'),
context = canvas.getContext && canvas.getContext('2d'),
data, width, height,
i = -4,
length,
rgb = {r:0,g:0,b:0},
@obj63mc
obj63mc / WP Author Search.php
Created November 15, 2017 16:36
Expand WP search to display posts by author when searched by author name
add_filter( 'posts_search', 'db_filter_authors_search' );
function db_filter_authors_search( $posts_search ) {
// Don't modify the query at all if we're not on the search template
// or if the LIKE is empty
if ( !is_search() || empty( $posts_search ) )
return $posts_search;
global $wpdb;
// Get all of the users of the blog and see if the search query matches either
@obj63mc
obj63mc / highcharts_date_display.md
Created November 15, 2017 16:36
PostPogo HighCharts display by specific date -

This will allow you to display data by date in clean formatting - replace the JQ selector as well the 'response' with the data for the series -

$('#site-stats').highcharts({
  chart: {
      zoomType: 'x'
  },
  title: {
      text: 'Posts per Day per Network'
  },

subtitle: {

@obj63mc
obj63mc / highcharts_hour_minute_display.md
Created November 15, 2017 16:36
PostPogo HighCharts to display by hour/minute

In this code you just need to replace the 'response' variable in the series with your data sets and change the JQ selector.

$('#site-stats').highcharts({
        chart: {
            zoomType: 'x'
        },
        title: {
            text: 'Posts per Day per Network'
        },

subtitle: {

@obj63mc
obj63mc / mongo_date_converion.md
Created November 15, 2017 16:36
Mongo DB Query to convert string to date and then aggregate by date.

Convert field from string to date -

db.post.find({postdate:{$type:2}}).sort({postdate:1}).forEach(function(p){p.postdate = new Date(p.postdate);db.post.save(p);});

Aggregate by that field -

db.post.aggregate([{$project:{day:{$dayOfMonth:'$postdate'},month:{$month:'$postdate'},year:{$year:'$postdate'}}}, {$group:{_id:{day:'$day',month:'$month',year:'$year'}, count: {$sum:1}}}])