|
import streamlit as st |
|
import random |
|
|
|
|
|
markdown_data = { |
|
"python": """ |
|
### Python - Top 10 Code Tips ๐ |
|
|
|
1. **Use virtual environments**: Keep dependencies isolated with `venv` or `conda`. ๐ ๏ธ |
|
2. **Utilize type hints**: Use Python's typing system for better code clarity and maintainability. ๐๏ธ |
|
3. **Leverage list comprehensions**: Write cleaner, more efficient loops. ๐ |
|
4. **Avoid mutable default arguments**: Use `None` instead of mutable objects as function defaults. ๐ซ |
|
5. **Use generators for large data**: Save memory with generator expressions and `yield`. ๐ก |
|
6. **Understand the difference between `==` and `is`**: Use `is` for identity checks, `==` for equality. ๐ |
|
7. **Use `enumerate()`**: Replace traditional `for` loops when needing indices. ๐งฎ |
|
8. **Try `dataclasses`**: Simplify class creation with Pythonโs `dataclass` decorator. ๐๏ธ |
|
9. **Use `f-strings`**: Format strings efficiently using `f"{value}"`. โจ |
|
10. **Write unit tests**: Test your functions with `unittest` or `pytest`. โ
|
|
""", |
|
|
|
"streamlit": """ |
|
### Streamlit - Top 10 Code Tips ๐๏ธ |
|
|
|
1. **Use `st.cache_data` for caching**: Cache expensive operations to speed up your app. โก |
|
2. **Utilize the session state**: Store data between reruns with `st.session_state`. ๐ |
|
3. **Leverage components**: Integrate React components with `streamlit-component-template`. ๐งฉ |
|
4. **Write custom widgets**: Expand functionality by creating custom Streamlit widgets. ๐ ๏ธ |
|
5. **Use layout options**: Design better apps with `st.columns` and `st.expander`. ๐ |
|
6. **Use interactive sliders**: Create smooth user interactions with `st.slider()`. ๐๏ธ |
|
7. **Handle forms properly**: Use `st.form()` for input forms to optimize reactivity. ๐ |
|
8. **Progress feedback**: Show progress with `st.progress()` and `st.spinner()`. ๐ |
|
9. **Embed HTML**: Enhance apps with `st.markdown()` using HTML inside markdown. ๐ |
|
10. **Deploy easily**: Use `streamlit.io` for one-click deployment. ๐ |
|
""", |
|
|
|
"typescript": """ |
|
### TypeScript - Top 10 Code Tips ๐ป |
|
|
|
1. **Use type annotations**: Always annotate variables and function return types. ๐ |
|
2. **Prefer interfaces over types**: Interfaces can be extended more easily than types. ๐ช |
|
3. **Use union and intersection types**: Combine types in flexible ways with `|` and `&`. ๐ ๏ธ |
|
4. **Utilize generics**: Write reusable functions and components with generics. ๐ |
|
5. **Avoid `any`**: Avoid using `any` type unless absolutely necessary. ๐ซ |
|
6. **Leverage optional chaining**: Safely access deeply nested properties. โ |
|
7. **Use `readonly` for immutability**: Enforce immutability with `readonly`. ๐ |
|
8. **Utilize `never` type**: Use `never` for unreachable code paths and exhaustive checks. ๐ง |
|
9. **Understand narrowing**: Use control flow analysis to narrow down types. ๐งฎ |
|
10. **Enable strict mode**: Always turn on strict mode for better type safety. ๐ก๏ธ |
|
""", |
|
|
|
"react_native": """ |
|
### React Native - Top 10 Code Tips ๐ฑ |
|
|
|
1. **Use `StyleSheet`**: Organize and optimize styles with `StyleSheet.create`. ๐จ |
|
2. **Avoid inline styles**: Use stylesheets for reusability and performance. ๐๏ธ |
|
3. **Leverage Flexbox**: Design responsive layouts with Flexbox. ๐ |
|
4. **Handle platform-specific code**: Use `Platform` module for OS-specific logic. ๐ ๏ธ |
|
5. **Optimize images**: Use `Image` and `ImageBackground` components efficiently. ๐ผ๏ธ |
|
6. **Utilize hooks**: Use hooks like `useEffect` and `useState` for state management. ๐ |
|
7. **Use third-party libraries**: Incorporate libraries like `react-navigation` and `redux`. ๐ |
|
8. **Optimize for performance**: Avoid unnecessary re-renders using `React.memo` and `useCallback`. ๐๏ธ |
|
9. **Handle gestures properly**: Use `react-native-gesture-handler` for gesture-based navigation. ๐ฒ |
|
10. **Utilize TypeScript**: Combine React Native with TypeScript for safer code. ๐ป |
|
""", |
|
|
|
"libraries": """ |
|
### Top 10 Python Libraries for SVG, TypeScript, and React Components ๐ ๏ธ |
|
|
|
1. **lxml**: Efficiently parse and manipulate XML, including SVG. ๐ |
|
2. **svgwrite**: Easily create and modify SVG files in Python. ๐ผ๏ธ |
|
3. **CairosVG**: Convert SVG files to various formats like PNG. ๐ |
|
4. **pydantic**: Handle data validation and complex typing in TypeScript code generation. โ
|
|
5. **datamodel-code-generator**: Automatically generate TypeScript code from Python data models. ๐ป |
|
6. **PyV8**: Run JavaScript code from within Python, useful for generating dynamic assets. ๐งโ๐ป |
|
7. **transcrypt**: Compile Python code to JavaScript for use with TypeScript projects. ๐ |
|
8. **reactpy**: Build interactive UIs using Python for web and mobile (React-like). ๐ฒ |
|
9. **react-native-svg**: Handle SVG assets in React Native applications. ๐ |
|
10. **streamlit-component-template**: Create custom React components inside Streamlit apps. ๐๏ธ |
|
""" |
|
} |
|
|
|
|
|
st.sidebar.title("Insights on Technologies ๐ ๏ธ") |
|
sections = ["Python Tips", "Streamlit Tips", "TypeScript Tips", "React Native Tips", "Python Libraries"] |
|
selected_section = st.sidebar.selectbox("Choose a Section:", sections) |
|
|
|
|
|
if selected_section == "Python Tips": |
|
st.markdown(markdown_data["python"]) |
|
elif selected_section == "Streamlit Tips": |
|
st.markdown(markdown_data["streamlit"]) |
|
elif selected_section == "TypeScript Tips": |
|
st.markdown(markdown_data["typescript"]) |
|
elif selected_section == "React Native Tips": |
|
st.markdown(markdown_data["react_native"]) |
|
elif selected_section == "Python Libraries": |
|
st.markdown(markdown_data["libraries"]) |
|
|
|
|
|
st.subheader("Interactive Code Examples ๐ป") |
|
tabs = st.tabs(["Python", "Streamlit", "TypeScript", "React Native"]) |
|
|
|
|
|
with tabs[0]: |
|
st.markdown(""" |
|
**Example: Python Generating TypeScript** ๐จ |
|
|
|
```python |
|
def generate_typescript_button(): |
|
return ''' |
|
import React from 'react'; |
|
import { Button } from 'react-native'; |
|
|
|
interface ButtonProps { |
|
title: string; |
|
onPress: () => void; |
|
} |
|
|
|
const CustomButton: React.FC<ButtonProps> = ({ title, onPress }) => ( |
|
<Button title={title} onPress={onPress} /> |
|
); |
|
|
|
export default CustomButton; |
|
''' |
|
``` |
|
""") |
|
st.button("Generate TypeScript Code ๐๏ธ") |
|
|
|
|
|
with tabs[1]: |
|
st.markdown(""" |
|
**Example: Custom Streamlit Widget** ๐๏ธ |
|
|
|
```python |
|
import streamlit as st |
|
|
|
def custom_button(label): |
|
st.write(f"Button: {label}") |
|
if st.button(label): |
|
st.write(f"Button {label} was clicked!") |
|
|
|
custom_button("Click Me") |
|
``` |
|
""") |
|
st.button("Generate Streamlit Code ๐ป") |
|
|
|
|
|
with tabs[2]: |
|
st.markdown(""" |
|
**Example: TypeScript Component in React Native** ๐ฑ |
|
|
|
```typescript |
|
import React from 'react'; |
|
import { View, Text, StyleSheet } from 'react-native'; |
|
|
|
const HelloWorld = () => ( |
|
<View style={styles.container}> |
|
<Text style={styles.text}>Hello, World!</Text> |
|
</View> |
|
); |
|
|
|
const styles = StyleSheet.create({ |
|
container: { |
|
flex: 1, |
|
justifyContent: 'center', |
|
alignItems: 'center', |
|
}, |
|
text: { |
|
fontSize: 24, |
|
color: 'blue', |
|
}, |
|
}); |
|
|
|
export default HelloWorld; |
|
``` |
|
""") |
|
st.button("Generate React Native Code ๐ฒ") |
|
|
|
|
|
with tabs[3]: |
|
st.markdown(""" |
|
**Example: React Native with TypeScript** ๐ป |
|
|
|
```typescript |
|
import React from 'react'; |
|
import { Text, View, Button } from 'react-native'; |
|
|
|
interface AppProps { |
|
title: string; |
|
} |
|
|
|
const App: React.FC<AppProps> = ({ title }) => ( |
|
<View> |
|
<Text>{title}</Text> |
|
<Button title="Click Me" onPress={() => alert('Button Pressed!')} /> |
|
</View> |
|
); |
|
|
|
export default App; |
|
``` |
|
""") |
|
st.button("Generate Full React Native App ๐ฒ") |
|
|
|
|
|
st.sidebar.info("๐ Enjoy exploring Python, Streamlit, TypeScript, and React Native!") |
|
|