Skip to content

Instantly share code, notes, and snippets.

@naanT
naanT / custom-domain-localhost-xampp
Created January 23, 2018 19:59 — forked from oozman/custom-domain-localhost-xampp
How to add a custom domain name on your localhost using XAMPP. Codes are based on Windows, but Step 2 onwards are pretty much applicable on other operating system.
Step 1:
Go to: C:\Windows\System32\Drivers\etc\hosts
And add this to the bottom of the file:
=============
127.0.0.1 your.domain.com
=============
Step 2:
Go to [your XAMPP directory]/apache/conf/httpd-xampp.conf
@naanT
naanT / onitemclicklistener_listview
Created August 21, 2015 02:08
onitemclicklistener listview android
forecastListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String forecastValue= (String) parent.getItemAtPosition(position);
Toast.makeText(getActivity(),forecastValue,Toast.LENGTH_LONG).show();
}
});
@naanT
naanT / HttpURLConnection
Created August 20, 2015 21:49
HttpURLConnection
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.connect();
// Read the input stream into a String
InputStream inputStream = urlConnection.getInputStream();
StringBuffer buffer = new StringBuffer();
if (inputStream == null) {
// Nothing to do.
return null;
@naanT
naanT / UriBuilder
Created August 20, 2015 21:46
UriBuilder
URL url = new URL("http://api.openweathermap.org/data/2.5/forecast/daily?q=94043&mode=json&units=metric&cnt=7");
final String FORECAST_BASE_URL =
"http://api.openweathermap.org/data/2.5/forecast/daily?";
final String QUERY_PARAM = "q";
final String FORMAT_PARAM = "mode";
final String UNITS_PARAM = "units";
final String DAYS_PARAM = "cnt";
Uri builtUri = Uri.parse(FORECAST_BASE_URL).buildUpon()
@naanT
naanT / AsyncTask
Created August 20, 2015 21:45
AsyncTask
public class FetchWeatherTask extends AsyncTask<String, Void, String[]> {
private final String LOG_TAG = FetchWeatherTask.class.getSimpleName();
/* The date/time conversion code is going to be moved outside the asynctask later,
* so for convenience we're breaking it out into its own method now.
*/
private String getReadableDateString(long time) {
// Because the API returns a unix timestamp (measured in seconds),
// it must be converted to milliseconds in order to be converted to valid date.
@naanT
naanT / .ArrayAdapter
Last active August 29, 2015 14:27
ArrayAdapter populating ListView
ListView forecastListView;
View view = inflater.inflate(R.layout.fragment_main, container, false);
String[] forecastData = {"Sunny", "Cloudy", "Warm", "Hot", "Cold"};
List<String> forecastList = new ArrayList<String>(Arrays.asList(forecastData));
forecastAdapter = new ArrayAdapter<String>(getActivity().getBaseContext(),
R.layout.list_item_forecast, R.id.list_item_forecast_textView, forecastList);
forecastListView = (ListView) view.findViewById(R.id.listView_forecast);