Skip to content

Instantly share code, notes, and snippets.

View coderinboots's full-sized avatar

CoderInBoots coderinboots

View GitHub Profile
@coderinboots
coderinboots / app.py
Last active March 26, 2019 17:50
Simple Python Flask application
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!. This is Systemd Example"
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8080)
@coderinboots
coderinboots / myapp.service
Created March 26, 2019 18:11
Run a flask application as a system service
[Unit]
Description=My Python Application
After=network.target
[Service]
Type=simple
# Another Type option: forking
User=amal
WorkingDirectory=/home/amal
ExecStart=gunicorn app:app --bind 0.0.0.0:8080 --workers 2
@coderinboots
coderinboots / raspberry_ops_python.py
Created September 27, 2020 05:30
Sample program to Turn ON and OFF LED in Raspberry Pi using python program. For more details visit https://www.coderinboots.com/
import RPi.GPIO as GPIO
from time import sleep
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(8,GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(10,GPIO.OUT, initial=GPIO.LOW)
while True:
GPIO.output(8,GPIO.HIGH) #Turn on GPIO pin 8 – changing LOW to HIGH
GPIO.output(10,GPIO.LOW) #Turn off GPIO pin 10 – changing HIGH to LOW
@coderinboots
coderinboots / list_splitter.py
Created September 27, 2020 14:07
Python program to split a larger list into a set of smaller lists. For more details, visit https://www.coderinboots.com
def divide_chunks(l, n):
"""
Function to split a larger list into a set of smaller lists
:param l: list
:param n: number of splits
:return: list of smaller lists
"""
# looping till length l
for i in range(0, len(l), n):
yield l[i:i + n]
@coderinboots
coderinboots / convert_df_to_list.py
Created September 28, 2020 04:04
Python program to convert a pandas dataframe into list of dictionaries. For more details, visit https://www.coderinboots.com
import pandas as pd
file_path = "data.csv"
delimiter = ","
required_fields = ["name", "emp_id"]
df = pd.read_csv(file_path, sep=delimiter, usecols=required_fields)
data_list = df.to_dict('records')
print("Record Count --->", len(data_list))
print(data_list)
@coderinboots
coderinboots / area_of_triangle.py
Created October 11, 2020 09:44
Python program to calculate the area of a triangle if we know all the sides
a = 5
b = 6
c = 7
s = (a + b + c) / 2
print("Value of s -->", s)
area = (s * (s-a) * (s-b) * (s-c)) ** 0.5
print("Area of triangle -->", area)
@coderinboots
coderinboots / python_dice_simulator.py
Last active October 19, 2020 03:33
Python program to simulate the dice rolling functionality. For more details, visit https://www.coderinboots.com
import random
roll_again = "yes"
while roll_again == "yes":
# Generates a random number
# between 1 and 6 (including
# both 1 and 6)
dice_value = random.randint(1, 6)