Skip to content

Instantly share code, notes, and snippets.

View omiq's full-sized avatar

Chris Garrett omiq

View GitHub Profile
@omiq
omiq / serial.py
Created March 27, 2018 23:35
Example of sending strings to Arduino over USB
import serial
import time
from datetime import datetime
print("Starting ...")
# change the port to whichever shows in Arduino
tardis = serial.Serial('/dev/ttyACM0', baudrate=9600)
while(1):
@omiq
omiq / menu.py
Created March 26, 2018 18:30
A Raspberry Pi/Linux Start Menu
import os
import readchar
# place in your start up file:
# sudo nano ./.bashrc
def menu():
while True:
os.system('clear')
@omiq
omiq / gyro.py
Created March 22, 2018 17:33
Example of using Grove sensors, displays and buttons with Python on Raspberry Pi
from LSM6DS3 import *
from time import sleep
from grove_rgb_lcd import *
import grovepi
# this is the chip the sensor is based on
mySensor = LSM6DS3()
# two buttons attached to digital 3 and 4
grovepi.pinMode(3, "INPUT")
@omiq
omiq / upload-wp-image.py
Created March 20, 2018 18:17
Upload images to WordPress and copy web URL to clipboard
import sys
import os
import requests
import pyperclip
# did the user supply an image file?
if len(sys.argv) == 2:
image = sys.argv[1]
else:
input("You must supply an image file!")
@omiq
omiq / readability.py
Created February 24, 2018 20:23
Version 2 - readability from a text file
# these modules help us do the script
import html2text
import requests
import sys
# this is the important library that acutally does the work
from textstat.textstat import textstat
with open('testfile.txt', 'r') as content_file:
test_string = content_file.read()
@omiq
omiq / bookmark-bot.py
Created February 21, 2018 21:03
Discord bookmark bot
import os
import sys
import discord
import subprocess
# discord client
client = discord.Client()
def process_message(message):
@omiq
omiq / readability.py
Last active February 19, 2018 19:33
Readability
# these modules help us do the script
import html2text
import requests
import sys
# this is the important library that acutally does the work
from textstat.textstat import textstat
# this is an easy way to strip html
h = html2text.HTML2Text()
@omiq
omiq / discord-bot.py
Created February 18, 2018 20:22
Discord Bot
import discord
# discord client
client = discord.Client()
# create a new event
@client.event
async def on_ready():
@omiq
omiq / thumb.py
Created January 24, 2018 20:16
How to Automagically Create Thumbnail Images Using Python
import glob
from PIL import Image
# get all the jpg files from the current folder
for infile in glob.glob("*.jpg"):
im = Image.open(infile)
# convert to thumbnail image
im.thumbnail((128, 128), Image.ANTIALIAS)
# don't save if thumbnail already exists
@omiq
omiq / rando_backlight.ino
Created January 23, 2018 22:12
Grove i2c LCD with random backlight colour
// libraries for i2c and the specific display
#include <Wire.h>
#include "rgb_lcd.h"
rgb_lcd lcd;
void setup() {
// make sure the random is random
randomSeed(analogRead(0));