Skip to content

Instantly share code, notes, and snippets.

View nelsonprsousa's full-sized avatar
:octocat:
Working from home

Nelson Sousa nelsonprsousa

:octocat:
Working from home
View GitHub Profile
@nelsonprsousa
nelsonprsousa / EnumerableExtensions.cs
Created May 30, 2023 18:59
ZipLongest returns a projection of tuples, where each tuple contains the N-th element from each of the argument sequences. The resulting sequence will always be as long as the longest of input sequences.
public static class EnumerableExtensions
{
public static IEnumerable<TResult> ZipLongest<TResult>(this IEnumerable<TResult> first, IEnumerable<TResult> second)
{
if (first == null)
{
throw new ArgumentNullException(nameof(first));
}
if (second == null)
@nelsonprsousa
nelsonprsousa / BaseLoader.cs
Last active January 29, 2022 18:19
Useful to avoid multiple requests to the same Task<T> (e.g. an HTTP GET operation). You probably want to registered the loader as a scoped or singleton service. Bare in mind that GetOrAdd is *not* atomic, although you can use your loader safely since it is thread-safe (usage of Lazy<Task<T>> to avoid multiple operations to resolve Task<T>).
public abstract class BaseLoader<T> : IBaseLoader<T>
where T : class
{
private readonly ConcurrentDictionary<string, Lazy<Task<T?>>> cache = new();
public Task<T?> LoadAsync(string key, Func<Task<T?>> factory)
{
return cache.GetOrAdd(key, (_) => new Lazy<Task<T?>>(factory)).Value;
}
}
namespace Wanderlust.API.Presentation.Queries;
using System;
using System.Threading;
using HotChocolate.Types.Pagination;
[ExtendObjectType(OperationTypeNames.Query)]
[GraphQLName(nameof(TodoQuery))]
public class TodoQuery
{
namespace Wanderlust.API.Presentation.Queries;
using HotChocolate.Types.Pagination;
[ExtendObjectType(OperationTypeNames.Query)]
[GraphQLName(nameof(TodoQuery))]
public class TodoQuery
{
[UsePaging]
public Connection<ITodoResult> GetTodos(string? after, int? first)
root = true
[*.yml]
indent_style = space
indent_size = 2
[*.cs]
charset = utf-8-bom
insert_final_newline = true
indent_style = space
var dataLoader = new DataLoader();
Console.WriteLine("Executing...");
var t1 = dataLoader.LoadAsync("1");
var t2 = dataLoader.LoadAsync("1");
var t3 = dataLoader.LoadAsync("9999");
Console.WriteLine("Done Loading...");
@nelsonprsousa
nelsonprsousa / DeleteLocalBranches.md
Created May 3, 2021 15:34
Delete all local branches but main

git for-each-ref --format '%(refname:short)' refs/heads | grep -v main | xargs git branch -D

onPress={() => {
// Navigation.showModal({
// component: {
// name: 'DescriptionScreen',
// options: {
// topBar: {
// visible: true,
// title: {
// text: 'Modal2',
// },
import React from 'react';
import {View, Dimensions} from 'react-native';
import Animated, {
useAnimatedScrollHandler,
useAnimatedStyle,
useSharedValue,
} from 'react-native-reanimated';
const BORDER_RADIUS = 10;
import React, { ReactElement } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createNativeStackNavigator } from 'react-native-screens/native-stack';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import Icon from 'react-native-vector-icons/Ionicons';
import Home from 'screens/home';
import Discover from 'screens/discover';
import Itinerary from 'screens/itinerary';
import Search from 'screens/search';