Skip to content

Instantly share code, notes, and snippets.

@keithweaver
keithweaver / objects-classes-in-python.py
Last active March 25, 2017 20:05
Example Objects within single file in Python
# This is an example of using Object/Classes in Python.
# The code has been tested with Python 2.7.
# My Car Object
class ExampleCarObject:
# This is the constructor so when creating the object, these are
# the required parameters. "self" is needed as the first parameter
# for all functions in the object but when call it, you do NOT
# pass anything in. At the bottom there is an example.
def __init__(self, carOwner):
@keithweaver
keithweaver / motor.py
Created April 4, 2017 04:41
Running Motor with Raspberry Pi
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BOARD)
Motor1A = 16
Motor1B = 18
Motor1E = 22
GPIO.setup(Motor1A,GPIO.OUT)
@keithweaver
keithweaver / 3sum.py
Last active April 17, 2017 21:54
3sum problem
'''
Given an array S of n integers, are there elements a, b, c in S such that
a + b + c = 0? Find all unique triplets in the array which gives the sum of
zero. Note, the solution must run in O(n^2logn) or O(n^2) time or better and
can use at most O(n) extra memory.
For example, given array S = [-1, 0, 1, 2, -1, -4],
A solution set is:
[
@keithweaver
keithweaver / folder-of-images-upload.py
Last active May 17, 2017 15:02
Upload a whole folder of images to the Haar Cascade Market via API
# This file will find keywords in the file name to assign tags for the
# Cascade Market. Add keywords to the image file name in the following
# format "..._keyword_keyword2.jpg". This is explained more below.
#
#
# Tips:
# - Keep it consistent. I made the mistake of labeling a mix of longboard and
# longboarder to represent the same thing. As a result, when I train I have
# to make sure the other is not in the negative set or it will affect my
# cascade.
<?php
// Install using composer and run: $ composer require kweaver00/lumberjack_php dev-master
require_once "/vendor/autoload.php";
$lumberjack = new \Kweaver\Lumberjack\Lumberjack();
$lumberjack->setAppKey("YOUR_APP_KEY");
$lumberjack->setAPIKey("YOUR_API_CODE");
$lumberjack->log("TAG","Content goes here.", "Verbose");
// Title, Content, Level of importance
@keithweaver
keithweaver / ls-example.py
Created October 3, 2017 11:33
Running the "ls" (list) command in Python
# Demo of using the ls command in Python
# https://stackoverflow.com/questions/4514751/pipe-subprocess-standard-output-to-a-variable
import subprocess
proc = subprocess.Popen('ls', stdout=subprocess.PIPE)
output = proc.stdout.read()
print output
# My terminal:
@keithweaver
keithweaver / ls-example2.py
Created October 3, 2017 11:39
Running the "ls" (list) command in Python for a specific directory
# Demo of using the ls command in Python
# I have another one here: https://gist.github.com/keithweaver/f77c5001e6e38b7c8fa5a4fb1505bc73
# But I really didn't want it to be the current path. I want to pass the path
# in. I found this example of listing all files in a path from SO:
# https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory
# Works perfect.
from os import listdir
from os.path import isfile, join
mypath = '../';
@keithweaver
keithweaver / test
Created October 26, 2017 20:05
Verifying my Blockstack ID is secured with the address 1AxH83ExEXXAwa86SASfSv3Pw1chXLAQNz https://explorer.blockstack.org/address/1AxH83ExEXXAwa86SASfSv3Pw1chXLAQNz
Verifying my Blockstack ID is secured with the address 1AxH83ExEXXAwa86SASfSv3Pw1chXLAQNz https://explorer.blockstack.org/address/1AxH83ExEXXAwa86SASfSv3Pw1chXLAQNz
@keithweaver
keithweaver / blockstack
Created November 27, 2017 02:52
blockstack
Verifying my Blockstack ID is secured with the address 13TYandebFM6qEWpekgneyCAmVGqgyibaM https://explorer.blockstack.org/address/13TYandebFM6qEWpekgneyCAmVGqgyibaM
@keithweaver
keithweaver / blockstack
Created November 27, 2017 15:01
blockstack
Verifying my Blockstack ID is secured with the address 1MrmdPKc3xb38HfwZbeeLSM4r42RhNU4tG https://explorer.blockstack.org/address/1MrmdPKc3xb38HfwZbeeLSM4r42RhNU4tG