Skip to content

Instantly share code, notes, and snippets.

View davestevens's full-sized avatar

Dave Stevens davestevens

View GitHub Profile
@davestevens
davestevens / LetsEncrypt.md
Last active March 28, 2024 10:35
Let’s Encrypt setup for Apache, NGINX & Node.js

Let's Encrypt

Examples of getting certificates from Let's Encrypt working on Apache, NGINX and Node.js servers.

Obtain certificates

I chose to use the manual method, you have to make a file available to verify you own the domain. Follow the commands from running

git clone https://github.com/letsencrypt/letsencrypt
cd letsencrypt
@davestevens
davestevens / README.md
Created February 19, 2021 17:01
Fetching all comments from a Reddit post

Reddit API

I could not find a simple example showing how to consume the Reddit API to get the comments for a post. This shows step by step how to authenticate and the endpoints to request.

Setup

You need to create an app to get an app id and secret. Go to https://www.reddit.com/prefs/apps and at the bottom of the page under "developed applications" create a new app or view a current one.

If you click "edit" to open the app view you will be able to see the app id and secret, these are required for authentication.

@davestevens
davestevens / download-images-from-google-drive.js
Last active March 15, 2023 16:20
Download images from Google Drive folder using Node.js Google library
var google = require("googleapis"),
drive = google.drive("v2"),
fs = require("fs");
var config = {
"client_id": "client_id",
"client_secret": "client_secret",
"scope": "scope",
"redirect_url": "redirect_rul",
"tokens": {
@davestevens
davestevens / index.html
Last active September 21, 2020 08:13
Render a DDS to HTMLImageElement
<!DOCTYPE html>
<html>
<head> </head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r120/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three-addons@1.2.0/build/three-addons.min.js"></script>
<script>
const loader = new THREE_ADDONS.DDSLoader();
loader.load("bucket.DDS", (texture) => {
texture.wrapT = THREE.RepeatWrapping;
@davestevens
davestevens / crop.php
Created November 5, 2012 11:41
Remove whitespace from around image.
<?php
/* Crop images */
/* Find whitespace around image and remove */
$border = 5;
/* Get image */
$orig = getImage($argv[1]);
@davestevens
davestevens / slack_notify.rake
Created February 18, 2015 18:15
Capistrano Slack integration.
# Capistrano Task that hooks into `deploy:finished` to send a message to Slack
#
# 1. Setup a Slack Incoming Webhook Integration (https://api.slack.com/incoming-webhooks)
# 2. Put the Webhook URL in an Environment variable (SLACK_WEBHOOK_URL)
# 3. Place this file in `lib/capistrano/tasks`
#
# This will then create a new message in the channel on deployment, including who, what and where information
require "net/http"
require "json"
require 'logger'
$logger = Logger.new(STDOUT)
require 'active_support/cache'
$cache = ActiveSupport::Cache.lookup_store(:memory_store)
$cache.logger = $logger
$cache.clear
class EtagMiddleware
@davestevens
davestevens / gist:8596770
Created January 24, 2014 13:00
Turtle Roy
penup
lt 180
fd 50
lt 180
lt 90
fd 50
rt 90
pendown
repeat 360(sequence[lt 1, fd 1])
fd 150
describe clCreateContext do
let(:params) { nil }
subject { clCreateContext(params) }
context "when calling with nil mooses" do
let(:params) { mooses: nil }
its(:errcode_ret) { should == CL_INVALID_MOOSE }
end
end
@davestevens
davestevens / gist:5029577
Created February 25, 2013 12:42
Setup jshint in emacs
This seems to run quicker than the jshint-mode example (https://github.com/daleharvey/jshint-mode) as it doesn't set up a node server each time.
1. Install node and get jshint
$ brew install node
$ npm install -g jshint
2. Update PATH to point to Node Packagem Manager bin directory