Skip to content

Instantly share code, notes, and snippets.

View finbarr's full-sized avatar

Finbarr Taylor finbarr

View GitHub Profile

Keybase proof

I hereby claim:

  • I am finbarr on github.
  • I am finbarr (https://keybase.io/finbarr) on keybase.
  • I have a public key whose fingerprint is D6C7 EA10 D18F D363 1BA7 22E6 9941 D223 4F7C 7D49

To claim this, I am signing this object:

@finbarr
finbarr / duplicates.rb
Last active August 29, 2015 14:04
Duplicates.
require "set"
def duplicates(array)
s = Set.new
array.each_with_object([]) { |a, d| (d << a) unless s.add?(a) }
end
@finbarr
finbarr / arraysort.rb
Created July 22, 2014 18:50
Array Sort
def arraysort(array)
result = []
array.each do |a|
if result[a].nil?
result[a] = [a]
else
result[a] << a
end
end
result.compact.flatten
@finbarr
finbarr / gist:da00c1c0f0c3cfcf2564
Last active August 29, 2015 14:06
Setting up country picker with current locale
// localeField is a UITextField
NSString *countryCode = [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode];
NSString *countryName = [CountryPicker countryNamesByCode][countryCode];
self.localeField.inputView = self.countryPicker;
self.localeField.text = [NSString stringWithFormat:@"%@ - %@", countryCode, countryName];
[self.countryPicker setSelectedCountryCode:countryCode];
@finbarr
finbarr / gist:cec3c89387c3cac7d5ad
Last active August 29, 2015 14:06
Changing the region of the phone field when the country is changed
- (void)countryPicker:(CountryPicker *)picker didSelectCountryWithName:(NSString *)name code:(NSString *)code
{
// ...
self.localeField.text = [NSString stringWithFormat:@"%@ - %@", code, name];
self.phoneNumberField = [[LTPhoneNumberField alloc] initWithFrame:self.phoneNumberField.frame regionCode:code];
// ...
}
@finbarr
finbarr / gist:401c1449ad102387a4b2
Created September 5, 2014 20:16
Getting the e164 and national numbers
NSString *e164 = [self.phoneNumberField phoneNumberWithFormat:LTPhoneNumberFormatE164];
NSString *formatted = [self.phoneNumberField phoneNumberWithFormat:LTPhoneNumberFormatNATIONAL];
@finbarr
finbarr / curl_format.txt
Created September 26, 2015 03:39
Curl Format
time_namelookup: %{time_namelookup}\n
time_connect: %{time_connect}\n
time_appconnect: %{time_appconnect}\n
time_pretransfer: %{time_pretransfer}\n
time_redirect: %{time_redirect}\n
time_starttransfer: %{time_starttransfer}\n
----------\n
time_total: %{time_total}\n
@finbarr
finbarr / shopify.md
Created October 22, 2015 03:05
How to fix Shogun page layout on Shopify

Click Online Store > Themes > Click '…' on the right > Edit HTML/CSS > Add a new Template > Create a new template for ‘page’ called ‘shogun’

Change the text in the box to this only:

{{page.content}}

Hit save and that should fix your problem. Please let me know if you need any more help.

class Array
def bucketize(n)
return [] if (buckets = n.to_i) <= 0
j = length / buckets.to_f
result = each_with_index.chunk { |_, i| (i / j).floor }.map { |_, v| v.map(&:first) }
result << [] until result.length == buckets
result
end
end
@finbarr
finbarr / gist:5715953
Created June 5, 2013 18:14
Stripe Transfer snippet.
stripe_transfer = Stripe::Transfer.create(
:amount => transaction_amount_in_cents,
:currency => 'usd',
:recipient => contractor.stripe_recipient_id,
:description => ''
)
#we store this after creating the transfer
stripe_tranfer.id