Skip to content

Instantly share code, notes, and snippets.

View julesce's full-sized avatar

James Thompson julesce

  • Hampshire, United Kingdom
View GitHub Profile
@julesce
julesce / gist:fa3a5ecfb0f7551169212389b3a8ddde
Last active September 18, 2025 07:57
The best recent novels to read this autumn
Drayton and Mackenzie. By Alexander Starritt. Swift Press; 512 pages; £16.99
Two very different men, James and Roland, meet as young adults. Both seek success, first as management consultants, then as entrepreneurs in the field of green energy. As they navigate private pain and the turmoil of the global financial crash of 2007-09, they increasingly value their friendship. Both characters are expertly drawn in this funny, touching story.
Dusk. By Robbie Arnott. Astra House; 272 pages; $26. Chatto & Windus; £16.99
A puma roams the Tasmanian highlands, killing sheep and their shepherds. Iris and Floyd, twins and social outcasts, join the hunt in hope of securing a considerable bounty. This brings them into contact with another tracker, Patrick, who is cunning and dangerous. This is a propulsive novel of survival and betrayal, enriched by arresting depictions of nature.
Flashlight. By Susan Choi. Farrar, Straus and Giroux; 464 pages; $30. Jonathan Cape; £20
One night, while on holiday in Japan, ten-year-old Lou
Plan for an explosion in personal wealth
By Magnus Heystek22 April 2021 12:35
The past ten years have not been a very good decade for most South African investors. Your pension and equity portfolio have not risen much over this period.
In fact, it was one of the lowest average ten-year returns in many decades. If inflation and transaction costs are taken into account, then most people today have much less in real terms than they think.
When the returns of the JSE over ten years are measured against the major world regions, the average returns were among the weakest in the world.
And as last week's article pointed out, yields in US dollar terms were round zero.
@julesce
julesce / try_vs_&&_vs_if.rb
Last active October 2, 2015 06:35
try vs && vs if
# Summary
# -------
# If you care about performance, use `&&` or an `if` statement instead of the object.foo.try(:name) pattern.
#
# Like so...
# object.foo.name if object.foo
# OR
# object.foo && object.foo.name
class Object
Promotion.find_each(:batch_size => 10) do |p|
if p.refreshing_stats?
date_refresh_started_at = p.retrieve_stats_cache_info(:refreshing => false)
if date_refresh_started_at
threshold_time = 6.hours.ago
if date_refresh_started_at < threshold_time
p.done_refreshing_stats
puts "Forced the completion of stats refresh for promotion #{p.id}"
end
EventMachine.run {
EventMachine::PeriodicTimer.new(60){
result = ActiveRecord::Base.connection.select_rows("show global status like 'threads_running'") # => [['threads_running', 1]]
threads_running = result.try(:first).try(:at, 1)
message = "#{threads_running} threads running at #{Time.now}"
puts message
file = File.open("#{Rails.root}/log/mysql_thread_count.log", 'a')
file.puts message
@julesce
julesce / gist:9763295
Last active August 29, 2015 13:57
RSS promotion default migrations
# This migration will loop through all RssPromotions and ensure that the default values from the 'unsent'
# mailing are correctly migrated to the new defaults created for RssPromotions, specifically:
# - new fields on the rss_promotion
# - rss_promotion has_and_belongs_to_many :audience_lists
# - rss_promotion has_and_belongs_to_many :audience_members
migrated_count = 0
RssPromotion.find_each do |rss_promotion|
mailing = rss_promotion.mailing
def async_save
json_v2_response_only do
json = JSON.parse(params[:promotion])
@promotion = current_user.promotions_find(json["id"])
validator = PromotionModuleValidator.new(@promotion, json)
if validator.valid?
@promotion.update_from_json(json, true)
# Update the mailing for the RSS Promotion when changing the promotion's name
>> mc = MembershipCampaign.find 54834774412
=> #<MembershipCampaign id: 54834774412, drip_campaign_id: 2686, membership_id: 3530060049, completed: true, created_at: "2012-11-05 11:48:23", updated_at: "2013-04-16 03:34:28">
>> am = mc.audience_member
=> #<AudienceMember id: 3470006376, user_id: 88088, first_name: "Miri", last_name: nil, email: "miriwageningen540@msn.com", created_at: "2012-11-05 11:48:23", updated_at: "2012-11-05 11:48:23", city: nil, created_by: "member", confirmed_at: nil, phone: nil, company: nil, title: nil, address: nil, state: nil, zip: nil, country: nil, aux_data: nil, ip: "85.130.200.159", suppressed: false, activation_code: nil, signup_id: 45146, confirmed: 1, rev_email: "", suppression_reason: nil, bounce_code: nil, soft: 0, deleted: 0, audience_import_id: nil>
>> RPromotionAttempt.find_all_keys_by_index(:audience_member_id, am.id)
=> ["267473035302864268", "370746214726985283"]
>> RPromotionAttempt.find_all_keys_by_index(:audience_member_id, am.id)
=> ["267473035302864268", "3707462
#
# There are a couple of drips that have not had their RLinkIndex created, since they are returning false for archived_mailing_links?
# This script attempts to fix this, by ensuring that the index is created, and archived_mailing_links? returns true
#
require 'logger'
Object.const_set(:RIAK_DISABLE_SECONDARY_INDEXES, false)
logger = Logger.new('log/fix_drip_clicks.log')
logger.info "====================== S T A R T ========================"
mailings_to_refresh = []
click_thrus_to_delete = []
promotions_to_refresh = []
ClickThru.find_each(:select => 'click_thrus.id, mailing_links.mailing_id',
:joins => "INNER JOIN mailing_links ON click_thrus.mailing_link_id = mailing_links.id",
:conditions => {:promotion_attempt_id => 9223372036854775807}) do |click_thru|
click_thrus_to_delete << click_thru.id
mailings_to_refresh << click_thru.mailing_id unless mailings_to_refresh.include?(click_thru.mailing_id)