Saturday, 18 January 2020
NativeBase Anatomy
NativeBase is a free and open source UI component library for React Native to build native mobile apps for iOS and Android platforms.
One of our main goal with NativeBase 2.0 is to make it easy to theme the components with very little changes to components themselves.
//cmd
npm install -g expo-cli
expo init native-base
cd native-base
npm install native-base --save
expo install expo-font
//app.js
import React from 'react';
import { Container, Header, Title, Content, Footer, FooterTab, Button, Left, Right, Body, Icon, Text } from 'native-base';
export default function App() {
return (
<Container>
<Header>
<Left>
<Button transparent>
<Icon name='menu' />
</Button>
</Left>
<Body>
<Title>Header</Title>
</Body>
<Right />
</Header>
<Content padder>
<Text>
This is Content Section
</Text>
</Content>
<Footer>
<FooterTab>
<Button full>
<Text>Footer</Text>
</Button>
</FooterTab>
</Footer>
</Container>
);
}
reference:
https://docs.nativebase.io/
One of our main goal with NativeBase 2.0 is to make it easy to theme the components with very little changes to components themselves.
//cmd
npm install -g expo-cli
expo init native-base
cd native-base
npm install native-base --save
expo install expo-font
//app.js
import React from 'react';
import { Container, Header, Title, Content, Footer, FooterTab, Button, Left, Right, Body, Icon, Text } from 'native-base';
export default function App() {
return (
<Container>
<Header>
<Left>
<Button transparent>
<Icon name='menu' />
</Button>
</Left>
<Body>
<Title>Header</Title>
</Body>
<Right />
</Header>
<Content padder>
<Text>
This is Content Section
</Text>
</Content>
<Footer>
<FooterTab>
<Button full>
<Text>Footer</Text>
</Button>
</FooterTab>
</Footer>
</Container>
);
}
reference:
https://docs.nativebase.io/
Friday, 17 January 2020
python threading
threading is better for IO-bound tasks. an IO-bound job is dominated by a lot of waiting on input/output to complete. multiprocessing is ideal for CPU-bound tasks.
import threading
start = time.perf_counter()
def do_something(num):
print(f'thread {num} starts...')
time.sleep(1)
with open('a.txt', 'a') as file:
file.writelines(f'running thread {num}\n')
print(f'Done thread {num}')
processes = []
if __name__ == '__main__':
for i in range(10):
p = threading.Thread(target=do_something, args=[i])
p.start()
processes.append(p)
for process in processes:
process.join()
finish = time.perf_counter()
print(f'finish in {round(finish-start, 3)} seconds')
-------------------------
#logs
thread 0 starts...
thread 1 starts...
thread 2 starts...
thread 3 starts...
thread 4 starts...
thread 5 starts...
thread 6 starts...
thread 7 starts...
thread 8 starts...
thread 9 starts...
Done thread 0
Done thread 1
Done thread 2
Done thread 4
Done thread 3
Done thread 9
Done thread 6
Done thread 8
Done thread 5
Done thread 7
finish in 1.019 seconds
#a.txt
running thread 0
running thread 2
running thread 1
running thread 4
running thread 3
running thread 7
running thread 6
running thread 5
running thread 9
running thread 8
reference:
https://www.youtube.com/watch?v=IEEhzQoKtQU
https://realpython.com/async-io-python/
#pycharm
import timeimport threading
start = time.perf_counter()
def do_something(num):
print(f'thread {num} starts...')
time.sleep(1)
with open('a.txt', 'a') as file:
file.writelines(f'running thread {num}\n')
print(f'Done thread {num}')
processes = []
if __name__ == '__main__':
for i in range(10):
p = threading.Thread(target=do_something, args=[i])
p.start()
processes.append(p)
for process in processes:
process.join()
finish = time.perf_counter()
print(f'finish in {round(finish-start, 3)} seconds')
-------------------------
#logs
thread 0 starts...
thread 1 starts...
thread 2 starts...
thread 3 starts...
thread 4 starts...
thread 5 starts...
thread 6 starts...
thread 7 starts...
thread 8 starts...
thread 9 starts...
Done thread 0
Done thread 1
Done thread 2
Done thread 4
Done thread 3
Done thread 9
Done thread 6
Done thread 8
Done thread 5
Done thread 7
finish in 1.019 seconds
#a.txt
running thread 0
running thread 2
running thread 1
running thread 4
running thread 3
running thread 7
running thread 6
running thread 5
running thread 9
running thread 8
reference:
https://www.youtube.com/watch?v=IEEhzQoKtQU
https://realpython.com/async-io-python/
Thursday, 16 January 2020
Subscribe to:
Posts (Atom)





