Setting ENV variables in XCode in not straighforward. I have broken down how to accomplish setting up an ENV variable in the following videos and code example.
Make a new conifuration file and set any ENV variables you need.
In the debug environment, use the debug.xcconfig file. Then, assign the value to something, in this case, SignUpUrl corresponds with the SIGN_UP_URL, which is set to localhost:4567/sign_up.
RSpec.describe'Donation Matching',:type=>:modeldocontext'with an amount'dolet(:donation){create(:donation,:with_amount)}endcontext'with no amount'dolet(:donation){create(:donation,:no_amount)}endend
However, I believe that using a shared context is a clearer approach. Defining the amount in a shared context and overriding the amount allows more control over testing use cases.
Using a shared context
donation_spec.rb
123456789101112131415161718
require'support/shared_contexts/donor_with_donation_context'RSpec.describe'Donation Matching',:type=>:modeldoinclude_context'a donor with a donation'context'with an amount'do//donation.amount==10(definedinthesharedcontext)endcontext'with no amount'dolet(:amount){0}//donation.amount==0endcontext'with a gnarly'dolet(:amount){09709780}endend
Finding auto layout information is difficult. The steps below pin a navigation bar to the top of the screen for all iOS devices.
Steps
Make sure “Navigation Bar” is selected on the left menu
Click the “Pin” button on the bottom right corner
Click the top, left and right constraints
Click the Height constraint
Add the 4 contraints
The above steps “pin” the navigation bar object to the top of the view and stretch the navigation bar to the sides of the view. The height constraint keeps a static height for the navigation bar.
I usually do not need to write code using neither constructors nor prototypes in Javascript. So, I always forget how to write them when I need to use them.
I have been using youtube-dl every week. The application is a “Small command-line program to download videos from YouTube.com and other video sites.” It’s super useful. However, it default downloads to the current terminal directory. Let’s write a simple shell script in order to place all downloaded files from youtube-dl in the same directory.
.zshrc
123456
function mp3 {# Download all of the things to /Downloads youtube-dl --default-search=ytsearch: \ --output="Downloads/%(title)s.%(ext)s""$*"}
The “$” signifies the string following mp3, the example below, “$” is the URL arument.
1
mp3 https://www.youtube.com/watch\?v\=9fYeiGeuTFA
Now I can run the above script in order to download the video from the youtube URL.!
At Fractured Atlas, we are trying to move away from the additional complexity of using callbacks. For example, let’s say we need to do something in a before_save callback such as lowercase a user’s email.
Now, when the email attribute is updated, my email setter method is called.
Currently, both implementations for downcasing an email are straightforward. However, as the application grows, the before_save callback is more difficult to test and maintain. The before_save is implicit and might have unexpected side effects. Here is a basic spec.
user_spec.rb
123456789101112
describeUserdolet(:user){FactoryGirl.create(:user)}describe'#lowercase_email'dobefore{user.email='GNARLY@email.com'}it'lowercases the email'doexpect(user.lowercase_email).toeq'gnarly@email.com'endendend
Instead, let’s test the behavior of what we expect.
user_creation_spec.rb
1234567891011
describe'User Creation'dolet(:user){FactoryGirl.create(:user)}describe':email'dobefore{user.email='GNARLY@email.com'}'it returns a standardized email'doexpect(user.email).toeq'gnarly@email.com'endendend
The first spec is directly testing the callback, whereas the latter spec is testing the behavior of the expected outcome. The latter spec is easier to reason about and change. This is an easy example, but as callbacks grow changing their behavior becomes more difficult. This is especially true if the callbacks are coupled with other models.
Now, if you copy and paste the the files into a XCode Playground, you can call methods on your person object.
Playground.swift
12345
person.count// 1person.first?.zip// 12345
Enums
An enumeration defines a common type for a group of related values and enables you to work with those values in a type-safe way within your code. - Swift docs
Use an enum when you need a consistent data value.
A struct allows you to create a structured data type which provides storage of data using properties and extending its functionality via methods. -Tree House
The goal of this blog is to refine my writing skills. In order to fulfill this goal I will write about something interesting I learned on a weekly basis. I find that if I do not get into a routine, I will not fulfill my goal. So, every Friday after work I will post on this blog. I have no goals about the legth of posts, but to write something with clarity and thoughfulness.
I inherited some interesting code last week. A user has the ability to sign into the website with omniauth.
1234567891011121314151617181920
defnumputs"Enter a number"num=gets.chomp.to_iifnum==3puts"It's a 3!"elseraise"Wrong number, you entered a #{num}"endenddefnum2numendbeginnum2rescueException=>exputsexend