Skip to content

Instantly share code, notes, and snippets.

View lesnitsky's full-sized avatar
:octocat:
Coding

Andrei Lesnitsky lesnitsky

:octocat:
Coding
View GitHub Profile
@lesnitsky
lesnitsky / lesnitsky.zsh-theme
Last active October 17, 2018 18:49
minimalistic zsh-theme
PROMPT='%{$fg[magenta]%}%c %{$fg[green]%}» %{$reset_color%}'
RPROMPT='%{$fg_bold[blue]%}$(git_prompt_info)%{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX=" #"
ZSH_THEME_GIT_PROMPT_SUFFIX=""
ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[red]%}✗%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN=" %{$fg[green]%}✓%{$reset_color%}"
root = true
[*]
end_of_line = lf
insert_final_newline = true
indent_style = tab
indent_size = 2

City center souvenir shops

// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Map<String, int> map = {};
int id = 0;
int getIdOrCreate(String key) {
if (map.containsKey(key)) {
return map[key];
} else {
id++;
map[key] = id;
return id;
@lesnitsky
lesnitsky / kIsWeb.dart
Last active January 20, 2020 11:09
How to detect if flutter app is running in web
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
const BE_HOST = 'https://api.dev';
class AppConfig {
static String BE_ENDPOINT;
}
@lesnitsky
lesnitsky / dart.json
Last active February 27, 2023 11:08
Flutter snippets
{
"JSON Serializable": {
"prefix": "jsons",
"body": [
"factory $1.fromJson(Map<String, dynamic> data) => _$$1FromJson(data);",
"Map<String, dynamic> toJson() => _$$1ToJson(this);"
]
},
"JSON Annotation": {
"prefix": "jsona",
@lesnitsky
lesnitsky / interrupt.dart
Last active April 22, 2020 14:52
llib:dart_utils
import 'dart:io';
import 'dart:async';
StreamTransformer<T, T> interrupt<T>() {
return StreamTransformer.fromHandlers(handleData: (data, sink) {
stdin.readLineSync();
sink.add(data);
});
}
@lesnitsky
lesnitsky / inherited_widget_override_example.dart
Last active May 26, 2020 12:35
InheritedWidget override
import 'package:flutter/material.dart';
class Service {
final String authToken;
Service({this.authToken});
getData() async {
if (authToken == null) {
fetchAnonymous();
} else {
@lesnitsky
lesnitsky / runtime_type_key.dart
Created September 30, 2021 12:51
runtimeType key
class Storage<T> {
final _internal = <Type, T>{};
void add(T value, [Type? type]) {
_internal[type ?? T] = value;
}
T get<T>() {
return _internal[T] as T;
}