Skip to content

Instantly share code, notes, and snippets.

View dcorking's full-sized avatar

David Corking dcorking

View GitHub Profile
@dcorking
dcorking / roassal-mondrian-movie-recommendations.st
Created May 6, 2017 08:07
interactive cluster graph (spider web) visualization of TMDb movie recommendations
"
For a workspace (aka playground)
Works in a Moose 6.0 image
dcorking, 2017, public domain Creative Commons CC0
"
path := '/Users/dcorking/workspace/tmdb-ruby-play/nodes.csv'.
stream := FileStream readOnlyFileNamed: path.
string := stream contents.
@dcorking
dcorking / one_liners.sh
Created August 3, 2016 08:12
One liners I wish I had thought of before now
# preview the most recently modified file in the current directory
ls -t |head -n 1 | xargs less # sadly less drops out on SIGINT
@dcorking
dcorking / gist:b563eb13bb3fd6a98deb
Created February 10, 2016 17:39
Error uploading to S3 with carrierwave and fog
# debug log using DEBUG=true EXCON_DEBUG=true rails s
Started PATCH "/admin/merchants/4/upload_logo?method=patch" for 127.0.0.1 at 2016-02-10 17:01:10 +0000
Processing by Admin::MerchantsController#upload_logo as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"Q6nXffNuL6KD368vHXTrTy5lPzV5udMD458mD3lMxAfdXxOcu5HcP9eL7o0J2AymKmA/sGQZUseLtpHsurBA8g==", "merchant"=>{"logo"=>#<ActionDispatch::Http::UploadedFile:0x00563ccc7ac6c8 @tempfile=#<Tempfile:/tmp/RackMultipart20160210-2362-17es9tm.jpeg>, @original_filename="demo-logo500px.jpeg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"merchant[logo]\"; filename=\"demo-logo500px.jpeg\"\r\nContent-Type: image/jpeg\r\n">}, "method"=>"patch", "id"=>"4"}
AdminUser Load (1.3ms) SELECT `admin_users`.* FROM `admin_users` WHERE `admin_users`.`id` = 18 ORDER BY `admin_users`.`id` ASC LIMIT 1
Merchant Load (1.2ms) SELECT `merchants`.* FROM `merchants` WHERE `merchants`.`id` = 4 LIMIT 1
(0.4ms) BEGIN
CACHE (0.1ms) SELECT `
@dcorking
dcorking / app_views_application__flashes.html.erb
Created February 10, 2016 12:14
Translate Rails flash key to metronic theme alert class
<% # Metronic theme alert classes can be used to style Rails 4 flash messages, for example like this. Render this partial from a page layout or page body. %>
<% if flash.any? %>
<div class="alerts">
<% user_facing_flashes.each do |key, value| -%>
<% # translate flash key to metronic alert class %>
<% # http://www.keenthemes.com/preview/metronic/theme/admin_1/ui_alerts_api.html %>
<% alert_class = {'alert' => 'alert-warning', 'notice' => 'alert-info'}[key] %>
<div class="alert <%= alert_class %>"><%= value %></div>
<% end -%>
@dcorking
dcorking / vagrant-bundler-problems-transcript.txt
Created December 10, 2014 11:35
Vagrant 1.6.5 works with Fedora 20 but Vagrant 1.7 and Vagrant 1.5 giving problems
###################################################################
### vagrant_1.5.4_x86_64.rpm
###################################################################
david1@localhost:~$ cd ~/workspace/24pullrequests/
david1@localhost:~/workspace/24pullrequests (master)$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'ubuntu/trusty64' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
@dcorking
dcorking / typecasting.c
Created August 2, 2014 20:40
Typecasting int to char in printf() in C
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
/* implements http://stackoverflow.com/questions/25079788/typecasting-int-to-char-in-printf-in-c */
/* by discussedtree */
/* Output is */
/* Int size in bits is: 32 */
/* Without typecasting, the integer at byte #0 is set to: 53200 */
@dcorking
dcorking / SqueakDebug.log
Created August 1, 2014 08:09
Unable to save a class comment
Error: RemoteString past end of file
1 August 2014 9:03:34.854 am
VM: unix - Smalltalk
Image: Squeak4.5 [latest update: #13687]
SecurityManager state:
Restricted: false
FileAccess: true
SocketAccess: true
@dcorking
dcorking / ruby-two-blocks-as-arguments.rb
Created July 3, 2014 05:58
A ruby method can accept two blocks as arguments, if we convert them to procs or lambdas
#!/bin/ruby
# Inspired by http://innig.net/software/ruby/closures-in-ruby
# Can this take 2 blocks?
# def apply_two_things(&block1, arg_after_block)
# end
# syntax error, unexpected ',', expecting ')'
# What about 2 procs?
@dcorking
dcorking / find_abuse.sh
Last active May 17, 2017 08:01
Notes on findutils
# This is not the official way to prune directories, but I found it easier.
# It prints the contents of all the files in the tree - excluding .git and CachedPixmaps,
# but there is a potential bug in the second globbed file name
#
# Works with GNU findutils. Might not work with BSD find, such as Mac OS X.
find -not -wholename './.git*' -not -wholename '*CachedPixmaps*' -type f |xargs cat
@dcorking
dcorking / seed_ops.rb
Last active August 29, 2015 14:03
Seed some volunteer opportunities
(5..20).each {|i| v = VolunteerOp.create :title => 'Voluntary helper', :description => 'Vivamus fermentum semper porta. Nunc diam velit, adipiscing ut tristique vitae, sagittis vel odio. Maecenas convallis ullamcorper ultricies. Curabitur ornare, ligula semper consectetur sagittis, nisi diam iaculis velit, id fringilla sem nunc vel mi. Nam dictum, odio nec pretium volutpat, arcu ante placerat erat, non tristique elit urna et turpis. Quisque mi metus, ornare sit amet fermentum et, tincidunt et orci. Fusce eget orci a orci congue vestibulum. Ut dolor diam, elementum et vestibulum eu, porttitor vel elit. Curabitur venenatis pulvinar tellus gravida ornare. Sed et erat faucibus nunc euismod ultricies ut id justo. Nullam cursus suscipit nisi, et ultrices justo sodales nec. Fusce venenatis facilisis lectus ac semper. Aliquam at massa ipsum. Quisque bibendum purus convallis nulla ultrices ultricies. Nullam aliquam, mi eu aliquam tincidunt, purus velit laoreet tortor, viverra pretium nisi quam vitae mi. Fusce vel volu