#Coding

HTTPS not working on AWS Elastic Beanstalk

by

Adding HTTPS to elastic beanstalk environment isn’t complicated to configure; until I fell into small mistake. Some of configuration dashboard’s flow been changed a bit from last time I setup the SSL certificate to a beanstalk environment.

Assumptions:

  • SSL certificate is ready from AWS Certificate manager.
  • Using lassic Load Balancer (Optional)
  • Configuration on application side is all fine.

Now assumption is we already have a SSL certificate created from AWS Certificate manager. We will head inside configuration of beanstalk environment. Under Load Balancer Configuration, we will add new lister that listens to HTTPS protocol at port 443. Under the settings, HTTP listener will already be added by default. Another assumption is that default security group added during creation of environment has all correct inbound rules to allow proper incoming access. Generally this is all taken care by beanstalk environment behind the scenes so we will not delve into too deep but focus on abstraction layer where making a mistake is easily susceptible to a new user.

CONTINUE READING

How to Get Substring With NSRange in Swift 5

by


Warning:

substring(with:)’ is deprecated: Please use String slicing subscript.

In Swift 5 we do no longer have access to substring() methods for they are deprecated. We will discuss all alternatives and understand them in details.

  • How to access Characters in String?
  • Why Int based Subscript is not available in Swift?
  • What is difference between Range and NSRange?
  • How does String Indices work?
  • How to create Range from String Indices?
  • How to get substring with Range?
  • How to get substring with NSRange?

CONTINUE READING

How to Fix Warning Attempt To Present UIAlertController in Swift

by

Warning: Attempt to present <UIAlertController: 0x7fa95080de00> on <MainViewController: 0x7fa94f8a5000> which is already presenting (null)

Warning of attempt to present view controller is common occurrence when making an easily made mistake. I will take Alert controller for an example to discuss.

Lets’s create a scenario to bring UIAlertController warning message and observe side effect to understand our situation more effectively. Then we will understand on how to fix warning attempt to present UIAlertController. I will present a Detail view controller modally from Main controller, and Main controller will be delegate object assigned to the property of Detail view controller. In our presented view controller I have a dismiss code when back button is pressed. Before dismissing the controller I will call the delegate object - Main controller in this case - to present Alert controller from Main controller.

CONTINUE READING

Mailto: Email Link Tricks in HTML

by

We use mailto links in html that opens default mail client app in the system. Mailto takes parameters that helps to create message with relevant fields already filled out for us.

But here’s the kicker: How do we create email message with all relevant fields filled out but without recepient name? We want user to fill recepient manually.

Now: First let’s see how mailto link is constructed -


<a href=“mailto:recepient@email.com?cc=first@email.com, second@email.com&bcc=gossip@email.com&subject=blah”>
Email Us
</a>

Common Mailto components are:

mailto:recepient@email.comRecipient address
cc=name@email.comCarbon copy e-mail address
bcc=name@email.comBlind carbon copy e-mail address
subject=subject textSubject of e-mail
body=body textBody of e-mail
?First paramter delimeter
&other parameters delimiter

Now comes the best part:

CONTINUE READING

CSS Hex Code Colors With Alpha Values

by

I use hex codes for color values - most of the part in my css than rgb or color name. We have limited named colors in css hence less color palette to work with so I generally don’t use them much frequently.

In rgb we have colors made of Red Green Blue channels. Values of each channel range from 0 to 255. In hex code, each digit contain values ranging from 0 - 9 and A - F - total 16 values. To represent each color channel we have two digit per channel that can provides us 256 combination of values.

Example:
FF is 240(15 * 161) + 15(15 * 160) = 255 (White)

Now we have #RRGGBB - two digit hex for each color channels.

CONTINUE READING

How to add social icons in Shopify programmatically?

by

We will add social media icons or buttons programmatically in html code of theme in Shopify. We are using free Debut theme. Our Debut theme does come with built-in most of the social icons. We will not be adding or uploading icon image files of our own. We will play with basic code and templating in Shopify.

The built-in social icons are all svg. We are glad they are svg. They are vector so works fluidly when adapting to any size we want it to be. It is very easy to customise the tint color by css or code. We don’t need separate image files for different colors or such. It is widely supported by all modern browsers.

All major files we work with are liquid files. Our whole theme customisation structure is built around Shopify’s liquid templating language that lets us work with all variables and objects to re-use without any heavy lifting work. Our built-in social media icons are in liquid files, which we will shortly see.

CONTINUE READING

MFMessageComposeViewController shows blank white screen issue

by

We use an MFMessageComposeViewController object to display the standard message composition interface in order to send text messages in our app. Properties of MFMessageComposeViewController lets us populate pre-defined recipients and body message before presenting the interface.

Simple code to create and present MFMessageComposeViewController is:

            
if([MFMessageComposeViewController canSendText]){
    MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
    picker.messageComposeDelegate = self;
    picker.recipients =@[“1234”];
    picker.body = @“pre-defined message”;
    [self presentViewController:picker animated:YES completion:nil];
}
else{
    NSLog(@“Cannot send text”);
}
            
            
            
if MFMessageComposeViewController.canSendText() {
    let picker = MFMessageComposeViewController()
    picker.messageComposeDelegate = self;
    picker.recipients =[“1234”];
    picker.body = “pre-defined message”;
    self.present(picker, animated: true, completion: nil)
}
else{
    print(“Cannot send text”);
}
            
            

Not so distant, I had stumbled upon a very silly mistake that caused an MFMessageComposeViewController to show blank after presenting.

CONTINUE READING

How to add social links programmatically from theme settings in Shopify

by

In visual editor of our basic free theme called Debut, we have feature to edit the information of social links that we want to use. This feature is in the social media settings inside theme settings of customisation.

When you save it. The value gets saved inside themes built-in settings liquid object. In our example here we are referring to Instagram link. Now for example if we are using Instagram url in our website in multiple places and with some custom layouts. Instead of copy pasting Instagram url into places, it would be much better if it was accessible from single liquid object. If in future Instagram link changes in one global place then it automatically updates throughout the website. This is just an example case scenario here and this can be used in many other situations.


CONTINUE READING

Show search button on safari keyboard in html

by

While working with search input in html form I came across steps of information that helped me manipulate iOS keypad. What do I mean by manipulating iOS keypad? It doesn’t mean changing anything about core physical appearance or device capability of software keyboard or device.

I have three requirements for when keypad is up when html input element is active:
  • Search should be the text over return/action button
  • When I press Search on keypad then action should take place or some event should fire off without redirecting or refreshing the page.
  • Lastly when I press ‘Search’ then keypad should also go down or dismissed.

CONTINUE READING

AVAudioPlayer not playing any sound

by

The most common culprit causing AVAudioPlayer not playing sound is ARC. When my audio player's scope is just within a function ARC deallocates the memory before playing sound after function is called. Here is an example code:


func playSoundEffect(assetName: string?) {
    if let sound = assetName{
        if let asset = NSDataAsset(name:sound){
            
            do {
                // Use NSDataAsset's data property to access the audio file stored in Sound.
                let soundEffect = try AVAudioPlayer(data:asset.data, fileTypeHint:"wav")
                // Play the above sound file.
                soundEffect?.play()
            } catch let error as NSError {
                print(error.localizedDescription)
            }
        }
    }
}

CONTINUE READING

Recommended posts