Skip to content

Instantly share code, notes, and snippets.

Avatar

Dan Lynn danlynn

View GitHub Profile
View csv-merge-like-columns.rb
require 'csv'
merged_file_path = '/Users/danlynn/Documents/temp/merge-csvs/ahoy_report-20200607-20200613-merge.csv'
file_paths = [
'/Users/danlynn/Documents/temp/merge-csvs/ahoy_report-20200607-20200613-interim.csv',
'/Users/danlynn/Documents/temp/merge-csvs/ahoy_report-20200607-20200613-legacy.csv',
'/Users/danlynn/Documents/temp/merge-csvs/ahoy_report-20200607-20200613-new.csv'
]
# Merge column titles from each file so that we can start
@danlynn
danlynn / console.sql
Last active Jun 12, 2020
mysql json queries
View console.sql
select properties->>"$.cow" from ahoy_events where properties->>"$.cow" is not null;
-- Finds rows where cow attr is not missing - BUT not where cow attr is not null
# null
# 1
# 2
# 3
# null
select properties->>"$.cow" from ahoy_events where properties->>"$.cow" != CAST('null' AS JSON);
-- Finds rows where cow attr is not missing - BUT not where cow attr is not null
View auto_clip_campaigns_controller.rb
# statuses:
# * Unclipped - Campaign has not been clipped yet
# - only the full mass clip will update this status - not the test clips
# - the show page hides the metrics and log
#
# * Clipping - Campaign is currently clipping the offers
# - full mass clip AND test clips will set this status
# - when full mass clip completes, status will update to Clipped
# - when test clips complete, status will update to Test Clipped
# - show the metrics and logs and run the ajax updates while in this state
View delete_duplicates.sql
create table test (
id int auto_increment primary key,
email varchar(20)
);
-- Query OK, 0 rows affected (0.02 sec)
insert into test
(id, email)
values
(1, 'aaa'),
View calc-upc-check-digit.js
function CalcCheckDigit(uncheckedUpc) {
let checkDigit = 0;
for (let i = 0; i < 11; i++) {
checkDigit += parseInt(uncheckedUpc.charAt(i)) * (i % 2 === 0 ? 7 : 9);
}
return checkDigit % 10;
}
View calc-upc-check-digit-bad.js
function CalcCheckDigit(strMsg){
// calculate the check digit - note UPCE and UPCA check digits are the same
var Check = 0; // initialize the check digit value
for(var X = 1; X <= 11; X++){
var Test = strMsg.substr(X-1, 1);
if (isOdd(X)==true){
Check = Check + parseInt(Test) * 7; // odd position digits multiplied by 7
}
else{
Check = Check + parseInt(Test) * 9; // even position digits multiplied by 9
View threadsafe.rb
# imagine this code ran in parallel by 2 threads in the same proc
@@credit = params[:credit]
thread.sleep(1) # lots of work going on here giving other thread chance to set balance from its request
account.balance += @@credit # reading value that might have been set by either thread last
account.save
View scopes.rb
$global_var = 'global'
class Foo
def self.class_var # note name start with 'self.' making this a class-level method
@@class_var
# would be error if tried to access @instance_var here since class knows nothing about any particular instance of class
end
def instance_var
@instance_var
end
View measure_elapsed_time.rb
require 'log4r'
def logger
@@logger ||= Logger.new("#{Rails.root}/log/some_profile.log")
end
def elapsed(start_time)
elapsed_secs = Time.now - start_time
"#{'%2d' % (elapsed_secs/60)}:#{'%02d' % (elapsed_secs%60)}:#{('%.4f' % (elapsed_secs - elapsed_secs.floor))[-4..-1]}"
end
View gist:685873d328aef7df115a

NFS Server

OS X Host

Note: you will need sudo access. Add the following to /etc/exports replacing the myunixuser with your own unix user account name

/Users -alldirs -maproot=myunixuser -network 192.168.99.0 -mask 255.255.255.0

Restart NFS: