Skip to content

Instantly share code, notes, and snippets.

View r3dm1ke's full-sized avatar
🎯
Before software can be reusable it first has to be usable.

Michael Krasnov r3dm1ke

🎯
Before software can be reusable it first has to be usable.
View GitHub Profile
def logging_decorator(func):
def logging_wrapper(*args, **kwargs):
print(f'Before {func.__name__}')
result = func(*args, **kwargs)
print(f'After {func.__name__}')
return result
return logging_wrapper
def log_all_class_methods(cls):
class NewCls(object):
@r3dm1ke
r3dm1ke / main.py
Last active October 26, 2020 15:50
class Logging:
def __init__(self, function):
self.function = function
def __call__(self, *args, **kwargs):
print(f'Before {self.function.__name__}')
self.function(*args, **kwargs)
print(f'After {self.function.__name__}')
def permission_decorator(permission):
def _permission_decorator(func):
def permission_wrapper(*args, **kwargs):
if someUserApi.hasPermission(permission):
result = func(*args, **kwargs)
return result
return None
return permission wrapper
return _permission_decorator
def timer_decorator(func):
def timer_wrapper(*args, **kwargs):
import datetime
before = datetime.datetime.now()
result = func(*args,**kwargs)
after = datetime.datetime.now()
print "Elapsed Time = {0}".format(after-before)
return result
@timer_decorator
@r3dm1ke
r3dm1ke / main.py
Last active October 30, 2020 01:17
def logging_decorator(func):
def logging_wrapper(*args, **kwargs):
print(f'Before {func.__name__}')
func(*args, **kwargs)
print(f'After {func.__name__}')
return logging_wrapper
@logging_decorator
def sum(x, y):
print(x + y)
import React, {Component, useState} from 'react';
// Class
class App extends Component {
constructor(props) {
super(props);
this.state = {counter: 0};
}
render() {
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'counter.dart';
void main() => runApp(CounterApp());
class CounterApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
class CounterPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final CounterBloc counterBloc = BlocProvider.of<CounterBloc>(context);
return Scaffold(
appBar: AppBar(title: Text('BLoC Demo')),
body: BlocBuilder<CounterBloc, int>(builder: (context, count) {
return Center(
child:
const App = () => {
const [resource, setResource] = useState(initialResource);
const [startTransition, isPending] = useTransition({timeoutMs: 1000});
return (
<>
<button
disabled={isPending}
onClick={() => {
startTransition(() => {
setResource(carResource);
import React, {Suspense} from 'react';
const cars = loadCarsFromServer(); // Start loading early
const App = () => (
<Suspense fallback={<h1>Loading cars</h1>}>
<CarDetails />
</Suspense>
);