Skip to content

Instantly share code, notes, and snippets.

View stuartbates's full-sized avatar

Stuart Bates stuartbates

  • London, United Kingdom
View GitHub Profile
/usr/bin/sqlite3 ~/Library/Application\ Support/Google/Chrome/Default/History <<EOF
select strftime('%Y%m', datetime(last_visit_time/1000000-11644473600, 'unixepoch')), count(distinct url) from urls where url LIKE 'https://stackoverflow.com%' group by 1;
EOF
suspend fun downloadMarker {
val furl = URL(myURL)
val bm = BitmapFactory.decodeStream(furl.openConnection().getInputStream())
return BitmapDescriptorFactory.fromBitmap(bm)
}
val bd = withContext(Dispatchers.IO) { downloadMarker() }
marker.setIcon(bd)

Keybase proof

I hereby claim:

  • I am stuartbates on github.
  • I am stuartbates (https://keybase.io/stuartbates) on keybase.
  • I have a public key whose fingerprint is 0D13 6F9D 6ED3 5DF7 3080 9ABD FA47 94AD 449C 4914

To claim this, I am signing this object:

@stuartbates
stuartbates / gist:61fda34f61b141028b76d3f5faaea5b7
Created December 14, 2016 17:17
A closer look at Ruby objects
class Student < User
has_many :class_groups
def high_achiever?
average_score > 75
end
end
hello@stuartbates.com Stuart Bates
@stuartbates
stuartbates / gist:d26f338775c5b32424eaa2bfc34105b4
Created July 28, 2016 08:07
Ideas for caching collection counts
# Hexdigest the params hash down to a string representation
params_digest = Digest::SHA1.hexdigest(params.to_s)
# Use the key in combination with namespace to create cache key
cache_key = "collection_counts.#{params_digest}"
# Cache the result using Redis.cache.fetch
# Set a sane default expiration period
Rails.cache.fetch(cache_key, expires_in: 12.hours) { scope.size }
class String
def arabic?
self[0,10].each_char.any? do |character|
character.ord.between?(65, 122) # Update numbers correctly
end
end
def english?
self[0,10].each_char.any? do |character|
@stuartbates
stuartbates / gist:c7f2704ec321aa073f35
Last active December 17, 2015 20:43
WALKTHROUGH: Creating new shipment from admin panel
# api/app/controllers/spree/api/shipments_controller.rb
def create
variant = Spree::Variant.find(params[:variant_id])
quantity = params[:quantity].to_i
@shipment = @order.shipments.create(:stock_location_id => params[:stock_location_id])
@order.contents.add(variant, quantity, nil, @shipment)
@shipment.refresh_rates
@shipment.save!
@stuartbates
stuartbates / gist:9d874abd3d5ea5fcfe1f
Created October 12, 2015 10:15
BAFTA Video Loader
<?php $classes = $challenge_video ? ' has-video' : ''; ?>
<div class="challenge-intro__image split-section__half">
<img class="challenge-intro__banner" src="/sites/all/themes/zen/library/img/deadline-bg.svg" alt="Challenge deadline banner" />
<time class="challenge-intro__deadline" datetime="<?php echo date('j-m-Y', $challenge_end_date); ?>"><?php echo date('jS M Y', $challenge_end_date); ?></time>
<div class="split-section__image-wrapper split-section__image-wrapper--large rounded-corners--border box-shadow--rounded-double js-play <?php echo $classes; ?>" data-embed="#challenge-video">
<?php echo '<img src="'.image_style_url('teaser_large', $challenge_image).'" alt="Latest challenge feature image" />' ?>
</div>
<?php echo $challenge_video; ?>
</div>
var $ = require('jquery');
require('jquery-ui/draggable');
require('jquery-ui/droppable');
require('remodal');
$(document).ready(function(){
$('.draggable').draggable();
$('.droppable').droppable({
drop: function(event, ui){