Skip to content

Instantly share code, notes, and snippets.

View felipeslongo's full-sized avatar
🌴
Having Fun With Threads

Felipe de Souza Longo felipeslongo

🌴
Having Fun With Threads
View GitHub Profile
@felipeslongo
felipeslongo / HtmlBuilder.java
Created February 19, 2018 21:06 — forked from Ilya-Gazman/HtmlBuilder.java
An easy way to work with HTML in Android. Just set the textView with the build result.
public class HtmlBuilder {
public static final String COLOR = "[color]";
public enum Type{
BOLD("strong"),
ITALIC("em"),
COLOR("font color=\"#"+ HtmlBuilder.COLOR + "\""),
SMALL("small")
;
public final String stringType;
@felipeslongo
felipeslongo / EachDirectoryPath.md
Created March 10, 2018 14:42 — forked from granoeste/EachDirectoryPath.md
[Android] How to get the each directory path.

System directories

Method Result
Environment.getDataDirectory() /data
Environment.getDownloadCacheDirectory() /cache
Environment.getRootDirectory() /system

External storage directories

@felipeslongo
felipeslongo / workaround.md
Created April 28, 2018 03:37 — forked from jimmgarrido/workaround.md
Broken Support Library Download Workaround

1. Go to %LOCALAPPDATA%\Xamarin

2. If it doesn't already exist, create a new folder named after the support library NuGet package, e.g. Xamarin.Android.Support.v4

3. Repeat for every support library package in your project:

4. Open the Xamarin Android SDK Manager and download the Android Support Repository (under Tools > Extras):

5. Go to [Android SDK location]\extras\android\m2repository\com\android\support and open the directory for the support library you need

6. Find the correct version and copy the entire folder to directory you created in step 2. The correct version is the one that matches or is nearest to the NuGet package version. For example, if the package version is 23.4.0.1 the support library version would be 23.4.0. If you did not create a folder in

@felipeslongo
felipeslongo / CustomerController.cs
Created May 24, 2018 04:25 — forked from vkhorikov/CustomerController.cs
Handling failures and input errors in a functional way
[HttpPost]
public HttpResponseMessage CreateCustomer(string name, string billingInfo)
{
Result<BillingInfo> billingInfoResult = BillingInfo.Create(billingInfo);
Result<CustomerName> customerNameResult = CustomerName.Create(name);
return Result.Combine(billingInfoResult, customerNameResult)
.OnSuccess(() => _paymentGateway.ChargeCommission(billingInfoResult.Value))
.OnSuccess(() => new Customer(customerNameResult.Value))
.OnSuccess(
@felipeslongo
felipeslongo / MakeBreakFast.cs
Created February 25, 2019 21:41
Breakfast Metaphor to explain async/await in C#
static void Main(string[] args)
{
var breakFast = await Task.Run( () => MakeBreakFast());
// once here I know breakfast is ready
Eat(breakFast);
}
private static async Task<BreakFast> MakeBreakFast()
{
var taskToastBread = ToastBreadAsync();
// do not await. As soon as the procedure awaits come back to do the next statement:
static void Main(string[] args)
{
var result = await SumAsync(1,2);
Console.WriteLine(result);
}
public static int Sum(int a, int b) => a + b;
public static Task<int> SumAsync(int a, int b) => Task.Run(() => Sum(a, b));
@felipeslongo
felipeslongo / AsyncAwaitFireAndForget.cs
Last active February 27, 2019 14:26
Fire and Forge: How it changes the way the caller works
static void async Main(string[] args)
{
await FireAndForget();
Console.WriteLine("Caller");
FireAndForget();
Console.WriteLine("Caller");
}
public static async Task FireAndForget()
static void async Main(string[] args)
{
try
{
await ThrowExceptionAfterAsync();
}
catch(Exception e)
{
//Gonna catch SHU
Console.WrileLine(e.Message);//SHU
@felipeslongo
felipeslongo / Task_FireAndForget.cs
Created March 6, 2019 20:27
Task FireAndForget Extension Method
static async void FireAndForget(this Task task)
{
try
{
await task;
}
catch (Exception e)
{
// log errors
}
@felipeslongo
felipeslongo / CultureInfo_Setters.cs
Last active March 13, 2019 17:29
Set CultureInfo for the entire application
using System.Threading;
namespace System.Globalization
{
public static class CultureInfo_Setters
{
public static void SetForApplication(this CultureInfo @this)
{
@this.SetForCurrentThread();
@this.SetForThreadPoolThreads();