Skip to content

Instantly share code, notes, and snippets.

View hjJunior's full-sized avatar

Helio S. Junior hjJunior

View GitHub Profile
@hjJunior
hjJunior / decorator.ts
Last active December 8, 2023 02:12
Typescript decorator
type DecorateClass<T extends {}, D extends Decorator<T>> = new (object: T) => D;
type DecoratedObject<T extends {}, D extends Decorator<T>> = T & D;
const decoratorHasProp = (decorator: Decorator, prop: string | symbol): prop is keyof typeof decorator => {
return Object.getPrototypeOf(decorator).hasOwnProperty(prop);
};
abstract class Decorator<T extends {} = {}> {
constructor(protected object: T) {}
@hjJunior
hjJunior / how-to-git-patch-diff.md
Created July 1, 2022 22:28 — forked from jplindgren/how-to-git-patch-diff.md
How to generate and apply patches with git? — First published in fullweb.io issue #33

How to generate and apply patches with git?

It sometimes happen you need change code on a machine from which you cannot push to the repo. You’re ready to copy/paste what diff outputs to your local working copy.

You think there must be a better way to proceed and you’re right. It’s a simple 2 steps process:

1. Generate the patch:

git diff &gt; some-changes.patch
@hjJunior
hjJunior / clampBuilder.js
Created February 7, 2022 18:15
Adjust the root text to be automatically responsible
function clampBuilder( minWidthPx, maxWidthPx, minFontSize, maxFontSize ) {
const root = document.querySelector( "html" );
const pixelsPerRem = Number( getComputedStyle( root ).fontSize.slice( 0,-2 ) );
const minWidth = minWidthPx / pixelsPerRem;
const maxWidth = maxWidthPx / pixelsPerRem;
const slope = ( maxFontSize - minFontSize ) / ( maxWidth - minWidth );
const yAxisIntersection = -minWidth * slope + minFontSize
const factorial = (number) => {
if (isNaN(number)) {
throw new Error(`"${number}" não é uma entrada valida`);
}
if (number == 0) {
return 1
}
return number * factorial(number - 1);
class User {
final String name;
final int age;
User({ this.name, this.age });
}
void main() {
final user = User(name: 'Helio', age: 10);
@hjJunior
hjJunior / dio_test.dart
Created November 2, 2019 19:03
An example how to use mockito and Dio to tests your calls to API
class DioAdapterMock extends Mock implements HttpClientAdapter {}
const dioHttpHeadersForResponseBody = {
Headers.contentTypeHeader: [Headers.jsonContentType],
};
void main() {
group('UserRemoteDataSource', () {
final Dio dio = Dio();
@hjJunior
hjJunior / inline-svg-function.scss
Created June 17, 2019 15:18 — forked from JacobDB/inline-svg-function.scss
Inline SVG function [SASS]
// Replace letters
@function str-replace($string, $search, $replace: '') {
$index: str-index($string, $search);
@if $index {
@return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
}
@return $string;
}
@hjJunior
hjJunior / myip.dart
Created June 10, 2019 19:20
Using IoC
class MyIp {
Injector get _injector => Injector.getInjector();
Client get _client => _injector.get<Client>();
Future<String> get ipAddress async {
final apiResult = await _client.get('https://api.ipify.org/?format=json');
return json.decode(apiResult.body)['ip'];
}
}
class MyIp {
Injector get _injector => Injector.getInjector();
Client get _client => _injector.get<Client>();
Future<String> get ipAddress async {
final apiResult = await _client.get('https://api.ipify.org/?format=json');
return json.decode(apiResult.body)['ip'];
}
}
@JsonSerializable(nullable: false)
class Person {
final String firstName;
final String lastName;
Person({this.firstName, this.lastName});
factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);
Map<String, dynamic> toJson() => _$PersonToJson(this);
}