Skip to content

Instantly share code, notes, and snippets.

View AndresR173's full-sized avatar

Andres Rojas AndresR173

View GitHub Profile
import 'package:flutter/material.dart';
class CurvePainter extends CustomPainter {
final Color paintColor;
CurvePainter(this.paintColor);
@override
void paint(Canvas canvas, Size size) {
final paint = Paint();
@AndresR173
AndresR173 / Box.swift
Created June 1, 2021 21:48
Boxing Technique
import Foundation
final class Box<T> {
typealias Listener = (T) -> Void
var listener: Listener?
var value: T {
didSet {
listener?(value)
}
@AndresR173
AndresR173 / http_service.dart
Created May 19, 2021 15:55
Http wrapper for Dart
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import '../../utils/constants.dart';
import '../../utils/error/failure.dart';
import '../../utils/extensions/extensions.dart';
import '../../utils/injection_container.dart';
@AndresR173
AndresR173 / nodejs-tcp-example.js
Created January 7, 2021 18:12 — forked from tedmiston/nodejs-tcp-example.js
Node.js TCP client and server example
/*
In the node.js intro tutorial (http://nodejs.org/), they show a basic tcp
server, but for some reason omit a client connecting to it. I added an
example at the bottom.
Save the following server in example.js:
*/
var net = require('net');
@AndresR173
AndresR173 / main.dart
Created November 5, 2020 13:59
Generics, Futures, Extensions in Dart
void main() async {
//Dynamic List
var list = [];
list.add(1);
list.add('2');
print(list);
// Callbacks
void downloadImage(Function(int) callback) {
int progress = 0;
@AndresR173
AndresR173 / dart.json
Last active May 7, 2021 17:48
VS Code - Dart Code Snippets
{
"triple_a_test": {
"prefix": "aaa",
"description": "AAA test",
"body": [
"test(",
"\t'should $1',",
"\t() async {",
"\t\t// arrange",
"\t\t$2",
@AndresR173
AndresR173 / google-config.file.sh
Created July 26, 2020 20:35
Copy Google-Services.plist into Xcode project from Flutter projects
# Type a script or drag a script file from your workspace to insert its path.
environment=${ASSET_PREFIX}
# Name and path of the resource we're copying
GOOGLESERVICE_INFO_PLIST=GoogleService-Info.plist
GOOGLESERVICE_INFO_FILE=${PROJECT_DIR}/Google/${environment}/${GOOGLESERVICE_INFO_PLIST}
# Make sure GoogleService-Info.plist exists
echo "Looking for ${GOOGLESERVICE_INFO_PLIST} in ${GOOGLESERVICE_INFO_FILE}"
@AndresR173
AndresR173 / TaskPropertyWrapper.swift
Created April 6, 2020 23:31
This example will show you how to use property wrappers to save Codable objects into UserDefaults
import Foundation
struct Task: Codable {
var title: String
var isDone: Bool
}
enum Errors: Error {
case encodeError
case decodeError
@AndresR173
AndresR173 / UserDefaultsPropertyWrapper.swift
Created April 6, 2020 12:57
How to use User Defaults with Property Wrappers
import Foundation
@propertyWrapper
struct UserDefaultsWrapper<Value: Codable> {
let key: String
let defaultValue: Value
let userDefaults = UserDefaults(suiteName: Constants.kGroupIdentifier)
var wrappedValue: Value {
get {
@AndresR173
AndresR173 / Demo.swift
Created February 12, 2020 15:07 — forked from AliSoftware/Demo.swift
NestableCodingKey: Nice way to define nested coding keys for properties
struct Contact: Decodable, CustomStringConvertible {
var id: String
@NestedKey
var firstname: String
@NestedKey
var lastname: String
@NestedKey
var address: String
enum CodingKeys: String, NestableCodingKey {