Skip to content

Instantly share code, notes, and snippets.

View isaacgr's full-sized avatar

Isaac isaacgr

View GitHub Profile
@isaacgr
isaacgr / extract.py
Created June 2, 2019 03:32
Script to move files out of a folder and into root directory
import shutil
import os
def main():
for root, dirs, files in os.walk(".", topdown=False):
for name in files:
if name.endswith('.bmp'):
thefile = os.path.join(root, name)
current_dir = os.getcwd()
shutil.move(thefile, current_dir)
import urlparse
import urllib2
import os
import sys
from bs4 import BeautifulSoup
import requests
import shutil
# url = raw_input("[+] Enter the URL: ")
url = "https://www.artic.edu/collection/more?is_public_domain=1"
@isaacgr
isaacgr / pdf_scrape.py
Created June 2, 2019 21:26
Script to download PDF files from a given url. Used it to download from MIT open courseware.
import urlparse
import urllib2
import os
import sys
from bs4 import BeautifulSoup
url = raw_input("[+] Enter the URL: ")
download_path = raw_input("[+] Enter the full download path: ")
@isaacgr
isaacgr / last_commit.py
Last active June 3, 2019 14:03
Get the date of the last commit for the current repository
import subprocess
import re
from optparse import OptionParser
def last_commit():
p = subprocess.Popen(["git", "log", '-1', '--date=iso'], stdout=subprocess.PIPE)
out, err = p.communicate()
m = re.search('\d{4}-\d{2}-\d{2}\s', out)
return m.group(0)
@isaacgr
isaacgr / streamer.sh
Created June 2, 2019 22:09
Use FFMPEG to convert an rtsp stream to hls and write output to m3u8 file.
#!/bin/sh
# Convert rtsp stream to hls and write to file
ffmpeg -i "rtsp://admin:admin@192.168.2.77:554/cam/realmonitor?channel=1&subtype=0" -c copy -hls_time 2 -hls_wrap 10 "/var/www/html/streaming.m3u8"
@isaacgr
isaacgr / client.service
Created June 2, 2019 22:13
Systemd service file. Includes environment variables and logging.
[Unit]
Description=Web Client Service
After=multi-user.target
Conflicts=getty@tty1.service
[Service]
Type=simple
# optional environment variable location which will be converted to variables readable by this file
# in this case $FLAGS
EnvironmentFile=/etc/default/webclient
@isaacgr
isaacgr / janus_test.py
Created June 2, 2019 22:21
Script to test that my janus server is actually up and running.
import requests
janus_ip = '192.168.2.48'
msg = {
'janus': 'create',
'transaction': 'test'
}
r = requests.post('http://%s/janus' % janus_ip, json=msg)
d = r.json()
@isaacgr
isaacgr / AuthHandler.js
Last active June 6, 2019 18:01
JSON Web Token authorization setup for webserver/webclient
import decode from "jwt-decode"
import jwt from "jsonwebtoken"
class AuthHandlder {
// Get a token from the server
login(username, password) {
const data = {
username,
password,
}
@isaacgr
isaacgr / logging_setup.py
Created June 7, 2019 16:03
Setup logging for python scripts
import logging
FORMAT = "%(asctime)s:%(levelname)s:%(name)s:%(message)s"
datefmt = "%Y-%m-%d-%H:%M:%S"
log = logging.getLogger(__name__)
logging.basicConfig(filename="output.log", level=logging.INFO,
format=FORMAT, datefmt=datefmt)
@isaacgr
isaacgr / arduino_json.cpp
Created June 8, 2019 03:32
Setup a json message buffer with ArduinoJson
#include <Arduino.h>
#include <ArduinoJson.h>
void setup()
{
Serial.begin(115200);
}
void loop(){
const size_t bufferSize = JSON_OBJECT_SIZE(5);