This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__}') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component, useState} from 'react'; | |
// Class | |
class App extends Component { | |
constructor(props) { | |
super(props); | |
this.state = {counter: 0}; | |
} | |
render() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const App = () => { | |
const [resource, setResource] = useState(initialResource); | |
const [startTransition, isPending] = useTransition({timeoutMs: 1000}); | |
return ( | |
<> | |
<button | |
disabled={isPending} | |
onClick={() => { | |
startTransition(() => { | |
setResource(carResource); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Suspense} from 'react'; | |
const cars = loadCarsFromServer(); // Start loading early | |
const App = () => ( | |
<Suspense fallback={<h1>Loading cars</h1>}> | |
<CarDetails /> | |
</Suspense> | |
); |
NewerOlder