File size: 8,502 Bytes
faed411
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import streamlit as st
import random

# Markdown data for insights
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. ๐ŸŽ›๏ธ
    """
}

# Set up the sidebar
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)

# Main content display
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"])

# Tabs for interactive code examples
st.subheader("Interactive Code Examples ๐Ÿ’ป")
tabs = st.tabs(["Python", "Streamlit", "TypeScript", "React Native"])

# Example Python code generation
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 ๐Ÿ–‹๏ธ")

# Streamlit Example
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 ๐Ÿ’ป")

# TypeScript Example
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 ๐Ÿ“ฒ")

# React Native Example
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 ๐Ÿ“ฒ")

# Footer
st.sidebar.info("๐ŸŽ‰ Enjoy exploring Python, Streamlit, TypeScript, and React Native!")