Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / drupal8_rest_api_create_node.py
Last active February 25, 2019 02:58
Drupal 8 REST API example
# Requires all 4 of the REST modules to be turned on
# HAL
# HTTP Basic Authentication
# RESTful Web Services
# Serialization
import requests
import json
@NanoDano
NanoDano / rpms_by_size.sh
Last active May 19, 2019 17:34
RPM list packages by size
# See which packages take up the most space
rpm -qa --queryformat '%10{size} - %-25{name} \t %{version}\n' | sort -n
# or simply
rpm -qa --queryformat '%{size} %{name}\n' | sort -n
# local_play.yaml
- name: Local play
hosts: localhost
connection: local
tasks:
- name: Create a text file
command: touch test.txt
- name: Rename the file
command: mv test.txt test.md