Skip to content

Instantly share code, notes, and snippets.

@beezee
beezee / domain_controller.erl
Created February 24, 2014 03:39
Chicago Boss universal RESTFUL json resource
-module(app_name_domain_controller, [Req]).
-compile(export_all).
all('GET', [Type]) ->
% TODO: expand flexibility of filtering interface
{json, boss_db:find(list_to_atom(Type), lists:map(fun({K, V}) -> {list_to_atom(K), 'equals', V} end,
Req:query_params()), [{order_by, last_update}, {order, desc}])}.
show('GET', [Id]) ->
Model = boss_db:find(Id),
@beezee
beezee / sync_wptt_post_counts.sql
Last active August 29, 2015 14:00
Synchronize wp_term_taxonomy post counts in one query
update wp_term_taxonomy as tt
left join (select term_taxonomy_id as tid, count(term_taxonomy_id) as real_count
from wp_term_relationships as tr
left join wp_posts as p on tr.object_id = p.ID
where p.post_status = "publish"
group by tid)
as rc
on rc.tid = tt.term_taxonomy_id
set tt.count = rc.real_count
@beezee
beezee / rchiper.rb
Created January 11, 2015 06:52
Rail Fence Cipher #rdaily
class RCipher
def take(s, n, stream)
x = 0
val = s
acc = []
while x < n do
val = stream.call(val)
acc.push(val)
x += 1
@beezee
beezee / no_side_effects.rb
Last active August 29, 2015 14:14
Putting your laundry away without side effects
# An exercise in controlled side effects inspired by
# http://tmd.io/code/2015/01/27/putting-away-your-laundry-a-look-at-service-objects-for-rails.html
# Generic "immutable" wrapper for hash of values and hash of validators
# Only unvalidated or Valid values come out of #to_h
# Validators can return ValidatedParams::Error('message') to come out of #errors
# This is a great candidate for property based testing and has no dependencies beyond hashes and procs
class ValidatedParams
Valid = true
$site_list = get_blog_list();
foreach ($site_list as $site)
{
switch_to_blog($site_list['blog_id']);
wp_signon($credentials);
}
restore_current_blog();
@beezee
beezee / sample node analytics query
Created February 6, 2012 17:14
max-results returns empty result
var mainQuery = {
'ids': 'FILL_THIS_IN',
'start-date': '2012-01-19',
'end-date': '2012-02-05'
'dimensions': 'ga:pageTitle,ga:hostName,ga:pagePath,ga:date',
'metrics': 'ga:pageviews,ga:visits,ga:timeOnSite',
'sort': '-ga:pageviews',
'max-results': 100000
};
@beezee
beezee / nGramr
Created March 19, 2012 18:57
caclulate every possible combination of n words up to x from a string
var nGramr = {}
nGramr.words = prompt('Whats the phrase?').split(' ');
nGramr.wordlen = nGramr.words.length;
nGramr.depth = prompt('Whats the n?');
nGramr.results = 0;
nGramr.grams = function(aWords) {
var words = aWords;
var depth = words.length;
console.log(depth);
_.each(nGramr.words, function(word) {
<script type="text/javascript">
function Drawium_explain_box_displayed(index){
console.log(index);
$("#binno-custom-tabs li").unbind('click.drawium');
if (index == 1) {
$(".drawium_next_button").remove();
$("#binno-custom-tabs li:nth-child(2)").bind('click.drawium', function() {
Drawer.tutorial_next();
});
}
<script type="text/javascript">
var tourApp = {
tabSteps: {
3: 'images',
10: 'users',
},
needsTweaking: function(i) {
return typeof tourApp.tabSteps[i] != 'undefined';
var tourApp = {
tabSteps: {
8: 'images',
12: 'users'
},
needsTweaking: function(i) {
return typeof tourApp.tabSteps[i] != 'undefined';
},