Skip to content

Instantly share code, notes, and snippets.

View Grohden's full-sized avatar
:shipit:
*tec tec tec noises*

Gabriel Rohden Grohden

:shipit:
*tec tec tec noises*
View GitHub Profile
@Grohden
Grohden / create-item.executor.ts
Last active July 21, 2021 13:41
Simple offline queue implementation for react native
import { createAsyncThunk } from '@reduxjs/toolkit';
import type { AppDispatch, RootState } from './my-store-file';
import { useAppDispatch } from './my-store-file';
import { useCallback } from 'react';
import { useOfflineExecutor } from './offline-executor';
import { createItem } from './create-item-slice.ts';
import { ItemService } from './services';
export type CreateItemThunkArg = {
@Grohden
Grohden / parallel_functions.py
Last active April 19, 2021 16:54
Promise.all like function for python running in threads
import concurrent.futures
from time import sleep
def expensive_computation(number):
sleep(10)
return number
class Runnable:
def __init__(self, original_target, *args, **kwargs):
self.original_target = original_target
{{>header}}
{{>part_of}}
class ApiClient {
ApiClient({this.basePath = '{{{basePath}}}'}) {
{{#hasAuthMethods}}
// Setup authentications (key: authentication name, value: authentication).
{{#authMethods}}
{{#isBasic}}
{{#isBasicBasic}}
_authentications[r'{{{name}}}'] = HttpBasicAuth();
@Grohden
Grohden / docs.json
Created November 26, 2020 03:07
Big treta com o openapi-generator
{
"openapi": "3.0.0",
"info": {
"title": "Foo",
"description": "Foo",
"version": "1.0",
"contact": {}
},
"tags": [],
"servers": [],
@Grohden
Grohden / useRefCallback.ts
Created October 29, 2020 14:23
Automatic ref callback for react
import { useRef, useCallback } from 'react';
/**
* Creates a stable callback pointing to the **latest
* render** [callback] provided to this function, making it stable
* without specifying deps.
*
* Note: Don't use this for render callbacks, this will cause
* renders to not update properly when state changes.
*/
@Grohden
Grohden / android-Appfile
Last active February 2, 2024 02:54
Release Flutter fastlane + azure pipelines (based on chimon2000/03b0fb1fa2f96c5933e3c9cb1ba59bc7 gist)
package_name("com.foo.bar")
@Grohden
Grohden / main.dart
Created October 2, 2020 17:21
Snippet showing method extension on dynamic with error
class Foo {
dynamic getA(){
return null;
}
}
extension IsNull on dynamic {
bool get isNull => this == null;
}
@Grohden
Grohden / main.dart
Created October 1, 2020 13:58
Snipped for is null problem
extension Nulls on dynamic {
bool get isNull => this == null;
}
class Foo {
String getA(){
return null;
}
}
@Grohden
Grohden / main.dart
Created September 6, 2020 17:58
Tricking type system with variance stuff
void main() {
var list = ['Jonny', 'Gabriel'];
Iterable list2 = Set<String>();
list = list2;
list.sort();
}
@Grohden
Grohden / main.dart
Created September 5, 2020 01:51
Sequential await vs non sequential
void main() async {
final list = [1,6,3,2,4,5];
print('Sequential');
for(final time in list) {
await Future.delayed(Duration(seconds: time));
print(time);
}
print('Not sequential');