Skip to content

Instantly share code, notes, and snippets.

@NanoDano
NanoDano / copy_recursive.py
Created November 13, 2018 05:58
Python 3 recursively copy one directory to another that may already exist
# copy_recursive.py
import os
import shutil
import sys
from pathlib import Path
def copy_recursive(source_base_path, target_base_path):
"""
Copy a directory tree from one location to another. This differs from shutil.copytree() that it does not
@NanoDano
NanoDano / stitch_images_into_timelapse_video.sh
Created June 5, 2018 04:40
Create timelapse video from still images
# Requires: sudo apt-get install mencoder
# To set it up to run on a cron job once per day at 5am:
# crontab -e
# 0 5 * * * /home/pi/timelapse_scripts/stitch_video.sh
DATE=`date '+%Y-%m-%d %H:%M:%S'`
echo "$DATE [*] Creating timelapse video"
cd /home/pi/Pictures
ls *.jpg > image_list.txt
@NanoDano
NanoDano / pi_take_timelapse_pic.sh
Created June 5, 2018 04:39
Raspberry Pi take timelapse pictures
# Take a picture with the Pi camera
# Set this script to run on a cron job
# crontab -e
# Every 5th minute
# */5 * * * /home/pi/timelapse_scripts/take_pic.sh 2>&1
DATE=`date '+%Y-%m-%d-%H-%M-%S'`
echo "$DATE [*] Taking picture"
raspistill -o /home/pi/Pictures/image-${DATE}.jpg
DATE=`date '+%Y-%m-%d-%H-%M-%S'`
@NanoDano
NanoDano / pi_cam_server.py
Last active May 27, 2018 00:38
Raspberry Pi camera viewing tool over HTTPS (Flask web server)
import os
from flask import Flask, render_template
from picamera import PiCamera, Color
BASE_DIR = '/home/pi/pycammy'
app = Flask(__name__)
camera = PiCamera()
@NanoDano
NanoDano / rmDirRecursive.js
Last active May 15, 2018 00:35
Recursive Delete Directory in Node.js
/**
* Clean out the build/ directory.
*
* npm run clean
*/
const fs = require('fs');
const path = require('path');
let buildDir = "build";
@NanoDano
NanoDano / nytimes_pull.py
Created October 13, 2016 03:38
Use the NYTimes API to query for articles in Python
import requests
import json
import time
MY_API_KEY = 'xxxx11234789012347891023478xxxxx'
def get_articles(api_key, category):
for i in range(0, 5):
url = 'http://api.nytimes.com/svc/search/v2/articlesearch.json'
url += '?/api-key=%s&fq=news_desk:("%s")&page=%s' % (api_key, category, i)
@NanoDano
NanoDano / selenium_ruby.rb
Created July 31, 2016 18:25
Ruby Selenium Example
require 'selenium-webdriver'
browser = Selenium::WebDriver.for :firefox
# Load a page
begin
browser.navigate.to 'http://www.devdungeon.com'
rescue
puts 'Error loading page.'
end
@NanoDano
NanoDano / is_jpeg.py
Created July 31, 2016 18:24
See if a file is a JPG with Python
#is_jpeg.py - Does the file have a JPEG binary signature?
import sys
import binascii
jpeg_signatures = [
binascii.unhexlify(b'FFD8FFD8'),
binascii.unhexlify(b'FFD8FFE0'),
binascii.unhexlify(b'FFD8FFE1')
]
@NanoDano
NanoDano / find_ascii_in_binary.py
Created July 31, 2016 18:24
Find ASCII characters in a binary file with Python
# find_ascii_in_binary.py - Identify ASCII characters in binary files
import sys
from functools import partial
chunk_size = 1
with open(sys.argv[1], 'rb') as in_file:
for data in iter(partial(in_file.read, chunk_size), b''):
x = int.from_bytes(data, byteorder='big')
if (x > 64 and x < 91) or (x > 96 and x < 123) :
@NanoDano
NanoDano / create_stego_zip_jpg.py
Created July 31, 2016 18:24
Create a stego image/zip archive with Python
# create_stego_zip_jpg.py - Hide a zip file inside a JPEG
import sys
# Start with a jpeg file
jpg_file = open(sys.argv[1], 'rb') # Path to JPEG
jpg_data = jpg_file.read()
jpg_file.close()
# And the zip file to embed in the jpeg