Skip to content

Instantly share code, notes, and snippets.

View maskaravivek's full-sized avatar
💭
Active!

Vivek Kumar Maskara maskaravivek

💭
Active!
View GitHub Profile
public static string TimeAgo(this DateTime dateTime)
{
string result = string.Empty;
var timeSpan = DateTime.Now.Subtract(dateTime);</code>
if (timeSpan &lt;= TimeSpan.FromSeconds(60))
{
result = string.Format("{0} seconds ago", timeSpan.Seconds);
}
else if (timeSpan &lt;= TimeSpan.FromMinutes(60)) { result = timeSpan.Minutes &gt; 1 ?
@maskaravivek
maskaravivek / post_request.cs
Last active August 23, 2022 09:15
Simple post request with multiple parameters in windows 8 metro app
string urlPath = "http://www.tiu.com/test/register.php";
var httpClient = new HttpClient(new HttpClientHandler());
var values = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("name", name),
new KeyValuePair<string, string>("email", email),
new KeyValuePair<string, string>("password",password)
};
HttpResponseMessage response = await httpClient.PostAsync(urlPath, new FormUrlEncodedContent(values));
response.EnsureSuccessStatusCode();
@maskaravivek
maskaravivek / windows8.cs
Created April 26, 2014 16:27
Getting simple string response from a web service in windows phone and windows 8 app
HttpClient http = new System.Net.Http.HttpClient();
string response = await http.GetStringAsync("http://www.tokkri.com/windowsphone/webservices/checkLogin.php?emailID=" + email + "&password=" + password);
@maskaravivek
maskaravivek / geo_distance.cs
Created April 27, 2014 01:12
How to find distance between two geo coordinates?
private double CalculateDistance(double prevLat, double prevLong, double currLat, double currLong)
{
const double degreesToRadians = (Math.PI / 180.0);
const double earthRadius = 6371; // kilometers
// convert latitude and longitude values to radians
var prevRadLat = prevLat * degreesToRadians;
var prevRadLong = prevLong * degreesToRadians;
var currRadLat = currLat * degreesToRadians;
var currRadLong = currLong * degreesToRadians;
MessageBoxResult res = MessageBox.Show("Ringtone Saved. Please take a moment to rate our app.It motivates us to make the list better.", "Free Ringtones", MessageBoxButton.OKCancel);
if (res == MessageBoxResult.OK)
{
MarketplaceReviewTask marketplaceReviewTask = new MarketplaceReviewTask();
marketplaceReviewTask.Show();
}
@maskaravivek
maskaravivek / home.html
Created April 30, 2014 20:58
applinks metadata
<html>
<head>
<meta property="al:android:url" content="https://play.google.com/store/apps/details?id=com.maplegraph.tokkri.core" />
<meta property="al:android:app_name" content="Tokkri" />
<meta property="al:android:package" content="com.maplegraph.tokkri.core" />
<meta property="al:windows_phone:url" content="www.windowsphone.com/en-in/store/app/tokkri/c2b4e3bb-5005-47f4-837b-1a9ecb7d5619" />
<meta property="al:windows_phone:app_name" content="Tokkri" />
<meta property="al:windows_phone:app_id" content="c2b4e3bb-5005-47f4-837b-1a9ecb7d5619" />
<meta property="al:web:url" content="http://www.tokkri.com" />
</head>
@maskaravivek
maskaravivek / string_to_stream.cs
Last active August 29, 2015 14:02
read large text to textblock in windows phone app
public Stream GenerateStreamFromString(string s)
{
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
}
@maskaravivek
maskaravivek / analytics.cs
Created June 19, 2014 07:07
google analytics tracking
private void Button_Click(object sender, RoutedEventArgs e)
{
GoogleAnalytics.EasyTracker.GetTracker().SendEvent("Button", "Click", null, 0);
try
{
//do something
}
catch (NotImplementedException exc)
{
GoogleAnalytics.EasyTracker.GetTracker().SendException(exc.Message, false);
@maskaravivek
maskaravivek / in_app_purchase.cs
Created June 21, 2014 13:33
in app purchases
public ObservableCollection<ProductItem> picItems = new ObservableCollection<ProductItem>();
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
RenderStoreItems();
base.OnNavigatedTo(e);
}
private async void RenderStoreItems()
{
@maskaravivek
maskaravivek / buy.cs
Created June 21, 2014 13:39
buy an item
private async void ButtonBuyNow_Clicked(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
string key = btn.Tag.ToString();
if (!Store.CurrentApp.LicenseInformation.ProductLicenses[key].IsActive)
{
ListingInformation li = await Store.CurrentApp.LoadListingInformationAsync();
string pID = li.ProductListings[key].ProductId;