Ignore Hidden Files When Using Git Add

I recently wanted to push some changes to Github, but I didn’t want to push all of my new files. I created a new folder using the cmd.exe with a ‘.’ in front of the name. All folders in Windows that have a ‘.’ in front of the name are ‘hidden’. Git will still be able to recognize the new folder, so before you add and commit, you can alter a file to say NOT to allow Git to add and commit hidden files/folders.

In the following file:

.git/info/exclude

Add this line after the comments:

.*

Save the file and all your hidden files/folders won’t be added by Git!

Advertisements

Show the Local Weather – Part 2

Read Part 1 here. Part 1 covers how to get a user’s geolocation to dynamically generate the weather according to the user’s location.

Part 2 is about using the user’s location to get the local weather forecast.

I used OpenWeatherMap‘s API to get the weather information. You’ll need to sign up (it’s free!) and get an API key: http://openweathermap.org/appid

  1. Sign up and get an API key from OpenWeatherMap.
  2. This is an example of the URL (API call) you will use to get weather info:
    http://api.openweathermap.org/data/2.5/weather?lat=33.7708&lon=-84.2931&units=imperial&APPID={APIKEY}

    This is the URL to OpenWeatherMap API:

    http://api.openweathermap.org/data/2.5/weather?

    You can use a city name, city ID, or longitude & latitude coordinates. I decided to use the longitude and latitude for more accurate weather.

    This is where you put the latitude and longitude coordinates.

    lat=11.111&lon=-11.111

    The longitude and latitude coordinates were derived from Part 1:

    {"ip":"8.8.8.8",
    "country_code":"US",
    "country_name":"United States",
    "region_code":"NY",
    "region_name":"New York",
    "city":"New York City",
    "zip_code":"10128",
    "time_zone":"America/New_York",
    "latitude":40.7142700,
    "longitude":-74.0059700,}

    You can also toggle Celsius and Fahrenheit with

    &units=

    Celsius: units=metric
    Fahrenheit: units=imperial

    Read more here.

    In place of {APIKEY} paste your OpenWeatherApp API key. You can find your key when you log into your account and go to the API Keys tab.

  3. Test your API call with Postman by placing the full URL ( http://…APPID=…..) in as a GET request. You should get a response similar to something like this:
    {"coord":{"lon":139,"lat":35},
    "sys":{"country":"JP","sunrise":1369769524,"sunset":1369821049},
    "weather":[{"id":804,"main":"clouds","description":"overcast clouds","icon":"04n"}],
    "main":{"temp":289.5,"humidity":89,"pressure":1013,"temp_min":287.04,"temp_max":292.04},
    "wind":{"speed":7.31,"deg":187.002},
    "rain":{"3h":0},
    "clouds":{"all":92},
    "dt":1369824698,
    "id":1851632,
    "name":"Shuzenji",
    "cod":200}

    Play around with different locations and when it is successful, you can go to the next step!

  4. Start writing your JavaScript function! We need to create an AJAX call to get the data returned from the API and store it in our own variables so we can use the information. I used the jQuery .ajax function.
    function getWeather(url) {
    	$.ajax({
    		url : url,
    		dataType : "json",
    		success : function(data) {		
    			var temp = data['main']['temp'];
    			var image = data['weather'][0]['icon'];
    			var desc = data['weather'][0]['description'];
    			var humidity = data['main']['humidity'];
    			var rain = data['weather'][0]['main'];
                            var sunset = new Date((data['sys']['sunset'])*1000);
                            sunset = sunset.toString().slice(16,21);
                            document.getElementById('image').src="http://openweathermap.org/img/w/" + image + ".png";
    			$('#temp').html(temp);
    			$('#desc').html(desc);
    			$('#wind').html(rain);
                            $('#sunset').html(sunset);
                            $('#humidity').html(humidity + "%");
    		}
    	});
    }

    The sunset variable is storing the sunset UNIX number and converting it to a readable format according to the user’s timezone.

    I am passing in the parameter to getWeather the URL saved as Weather in Part 1. It’s the URL you use to make the weather API call.

To load OpenWeatherMap’s weather icons, use this img source format:

http://openweathermap.org/img/w/" + image + ".png";

Where:

var image = data['weather'][0]['icon'];

Final Product: http://sunsplat.github.io/fcc_weather/index.html

Source for how to get the weather icons here: https://openweathermap.desk.com/customer/portal/questions/13287488-weather-icon-id

Another weather API you can use: forecast.io

Show the Local Weather

This is Part 1 explaning the steps I took to complete the Show the Local Weather challenge from FreeCodeCamp‘s Intermediate Front-End Development Projects section. Part 1 consists of getting a user’s geolocation dynamically. Part 2 Part 2 will be about how to use OpenWeatherMap’s API in your app.

I used Postman to check API connectivity and to get the JSON objects. You can also simply use your browser to do the checks.

  1. First I created the site layout for my weather app using Bootstrap. This way I could play with where I wanted the person’s location to appear and how I wanted to show the weather. I used HTMLshell to quickly paste the usual tags.
  2. I created an empty CSS file and an empty JS file and included the links in my main index.html file.
  3. Then I wanted to add a button that could toggle Celsius and Fahrenheit. I needed to add JavaScript to be able to toggle the action when a user clicks the toggle button.
  4. After getting the button to work, I focused on how to get the user’s location. I used http://freegeoip.net/ to grab a user’s IP address and use that to determine their location. It’s less accurate than Google’s Geolocation, but you can scroll to the bottom to read why that isn’t so simple to implement in Chrome since Spring this year.I knew I was using JSON so I used the url:
    freegeoip.net/json/

    When passing this url, freegeoip will automatically grab the user’s IP and return a JSON object similar to this:

    {"ip":"8.8.8.8",
    "country_code":"US",
    "country_name":"United States",
    "region_code":"NY",
    "region_name":"New York",
    "city":"New York City",
    "zip_code":"10128",
    "time_zone":"America/New_York",
    "latitude":40.7142700,
    "longitude":-74.0059700,}

    If you are using Postman, you can play around with what the response is by sending a GET to:

    //location info for freecodecamp.com
      freegeoip.net/json/freecodecamp.com
    
    //location info for your location
      freegeoip.net/json/
    
    //location info for yahoo.com
      freegeoip.net/json/yahoo.com
  5. Once you are successfully able to get the JSON object info, you can start creating your AJAX call in your JS file. I created a function called getLocation() to contain the information. I used the jQuery function $.ajax to get the data. Can also reference this. Make sure to include the jQuery link in the <head> of your html file or it won’t work!
     https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js

    This is the $.ajax template:

    $.ajax({
      dataType: "json",
      url: url,
      data: data,
      success: success
    });

    This is what my function looks like:

    var locateUser = 'http://freegeoip.net/json/';
    
    function getLocation() {
      $.ajax({
        url : locateUser,
        dataType : "json",
        success : function(data) {
        var country =data['country_code'];
        var region = data['region_code'];
        var city = data['city'];
        var latitude = data['latitude'];
        var longitude = data['longitude'];
        $('#location').html(city + ', ' + region);
        var Weather = "http://api.openweathermap.org/data/2.5/weather?lat=" + latitude + "&lon=" + longitude + "&APPID=" + OpenWeatherKey;
    getWeather(Weather);
        }
      });
    }

    The ‘#location’ id is tied to the <div> where I want the City, Region to appear on my website.

  6. The next step is to grab the weather for the location data you just stored!

Read Part 2: Getting the Weather Information here.

Final Product: http://sunsplat.github.io/fcc_weather/index.html

Note: When attempting to complete this challenge, do not use Google’s Geolocation as since May 2016, they require do not work over insecure domains (must use HTTPS). Free SSL here.

If you insist on trying to implement Google’s Geolocation, you can sign up for an API key here: https://console.developers.google.com. Then follow Udacity’s really great tutorial on using it: https://www.udacity.com/course/google-maps-apis–ud864.

Keep in mind that Chrome and Safari (webkit browsers) do not allow Geolocation API for files that are local. Geolocation WILL work in Internet Explorer as of this posting.


Another weather API you can use: forecast.io
Another IP geolocation API: http://ipinfo.io/


See https://developers.google.com/web/updates/2016/04/geolocation-on-secure-contexts-only for details.

https://www.chromium.org/Home/chromium-security/education/tls#TOC-TLS-Resources-for-Developers-and-Site-Operators

https://mobiforge.com/news-comment/no-https-then-bye-bye-geolocation-in-chrome-50

https://developers.google.com/maps/documentation/geocoding/start?csw=1#reverse

 

 

OpenWeatherMap API in Postman

How to use Postman to test the OpenWeatherMap API:
1. First go to the OpenWeatherMap website, click on ‘Subscribe’ under ‘Current weather data’ and sign up for a free API key:
2. Then when you are logged in, navigate to the API Keys tab:
Unnamed QQ Screenshot20160606225904

3. My key is not showing above, but you would want to copy that key.

4. To learn more on how to use the API key in OpenWeatherApp, you can go here:
http://www.openweathermap.com/appid#use

To make an API call (directions in the URL above), use this example:
http://api.openweathermap.org/data/2.5/forecast/city?id=524901&APPID={APIKEY}

Where {APIKEY} should be replaced with the key you copied in step 3.

5. Open Postman and past the whole URL into the GET ‘Enter request URL’ field like so:
Unnamed QQ Screenshot20160606230526

You’ll be able to see the object result.

Read more here.

Really helpful intro to API’s.

Back Coding

I’m back at it!

It’s been so long since I’ve updated this blog. I had been so busy over the 2015 holiday season searching and applying for jobs. I finally got my first developer job in February and started on February 29, 2016. It’s been so exciting to finally get to apply what I’ve been learning in a real-world setting, solving real problems and trying to find creative solutions.

I’ve learned a lot about databases hosted by SQL Server and Oracle, the differences and similarities. It’s been interesting searching, joining, manipulating data. Although I don’t know where my career is headed, as it’s still early, I’m excited to have found a job doing something I enjoy and am looking forward to seeing what’s next!

I started my career change, learning HTML and CSS back in April 2015. It took me about 10 months since starting to get my first job as a junior developer. I would say the thing that helped me the most was NETWORKING. Get on Meetup.com and go to as many tech meetups as you can. Search for ‘Ruby’, ‘PHP’, ‘Web Development’, ‘Agile’, JavaScript’. Go on Facebook and add ‘Newbie Coder Warehouse’. Search for FreeCodeCamp in your city on Facebook. They are bound to have an online community. Talk to all the recruiters that introduce themselves. Get to know the hosts and regular attendees. They will be the ones that will think of you when they hear of an opening.

YOU CAN DO IT!