Skip to content

Instantly share code, notes, and snippets.

View dangayle's full-sized avatar

Dan Gayle dangayle

View GitHub Profile
@dangayle
dangayle / nginx-mobile-redirect
Created June 12, 2012 18:24
NGINX Mobile redirect
#with regex from http://detectmobilebrowsers.com/
#map suggestion via kolbyjack
#not tested
map $http_user_agent $mobile_agent{
default 0;
~* "android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino" 1;
~* "^(1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibr
@dangayle
dangayle / subreddit_latest.py
Created February 24, 2016 00:58
Get all available submissions within a subreddit newer than x
import sys
from datetime import datetime, timedelta
import praw
user_agent = "hot test 1.0 by /u/dangayle"
r = praw.Reddit(user_agent=user_agent)
class SubredditLatest(object):
"""Get all available submissions within a subreddit newer than x."""
@dangayle
dangayle / app.js
Created January 2, 2017 22:28
Loading Tachyons using Webpack and React
import React from 'react';
import Tachyons from 'tachyons/css/tachyons.min.css'
const App = () => (
<div className="mw9 center">
<h2 className="red sans-serif tc">Hello, world</h2>
</div>
);
export default App;
@dangayle
dangayle / twitterbot.py
Last active September 9, 2021 03:06
Twitter bot that tweets a random line from a file. Uses Twisted to periodically select a random line from an input file, and Twython to post it to Twitter using your credentials. Usage: python twitterbot.py file.txt, where each line in file.txt is a single sentence terminated by a newline ('\n').
"""Twitter bot that tweets a random line from a file.
Uses Twisted to periodically select a random line from an input file,
and Twython to post it to Twitter using your credentials.
Usage: python twitterbot.py file.txt, where each line in file.txt is
a single sentence terminated by a newline ('\n').
"""
import sys
@dangayle
dangayle / golden_ratio.scss
Last active June 24, 2021 22:56
The only css grid you need, based on the golden ratio.
$grid-gutter-width: 30px;
.l-1{
// larger portion of golden ratio
width: calc(#{percentage(1/1.618)} - #{$grid-gutter-width / 2});
}
.l-2{
// Smaller portion of golden ratio
width: calc(#{percentage(1-1/1.618)} - #{$grid-gutter-width / 2});
}
from app import db
from sqlalchemy import func, types
from sqlalchemy.dialects import postgresql
class JSONCache(db.Model):
id = db.Column(db.Integer, primary_key=True)
key = db.Column(db.String, nullable=False, index=True)
data = db.Column(postgresql.JSONB, nullable=False)
timestamp = db.Column(types.TIMESTAMP, server_default=func.now(), nullable=False)
@dangayle
dangayle / README.md
Created April 24, 2019 21:00 — forked from mrbar42/README.md
bash scripts to create VOD HLS stream with ffmpeg almighty (tested on Linux and OS X)

running:

bash create-vod-hls.sh beach.mkv

will produce:

    beach/
      |- playlist.m3u8
 |- 360p.m3u8
@dangayle
dangayle / ffmpeg.sh
Created March 2, 2019 00:51 — forked from crookm/ffmpeg.sh
FFmpeg commands to create DASH and HLS
mkdir dash && \
ffmpeg -hide_banner -i original.mkv -c:v libvpx-vp9 -row-mt 1 -keyint_min 150 -g 150 -tile-columns 4 -frame-parallel 1 \
-movflags faststart -f webm -dash 1 -speed 3 -threads 4 -an -vf scale=426:240 -b:v 400k -r 30 -dash 1 dash/426x240-30-400k.webm && \
ffmpeg -hide_banner -i original.mkv -c:v libvpx-vp9 -row-mt 1 -keyint_min 150 -g 150 -tile-columns 4 -frame-parallel 1 \
-movflags faststart -f webm -dash 1 -speed 3 -threads 4 -an -vf scale=426:240 -b:v 600k -r 30 -dash 1 dash/426x240-30-600k.webm && \
ffmpeg -hide_banner -i original.mkv -c:v libvpx-vp9 -row-mt 1 -keyint_min 150 -g 150 -tile-columns 4 -frame-parallel 1 \
-movflags faststart -f webm -dash 1 -speed 3 -threads 4 -an -vf scale=640:360 -b:v 700k -r 30 -dash 1 dash/640x360-30-700k.webm && \
ffmpeg -hide_banner -i original.mkv -c:v libvpx-vp9 -row-mt 1 -keyint_min 150 -g 150 -tile-columns 4 -frame-parallel 1 \
-movflags faststart -f webm -dash 1 -speed 3 -threads 4 -an -vf scale=640:360 -b:v 900k -r 30 -dash 1 dash/640x360-30-900k.we
@dangayle
dangayle / isElementInViewport.js
Created January 4, 2019 03:54 — forked from davidtheclark/isElementInViewport.js
JavaScript: Is element in viewport?
/*
No jQuery necessary.
Thanks to Dan's StackOverflow answer for this:
http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport
*/
function isElementInViewport(el) {
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
@dangayle
dangayle / classify_startstop.py
Created May 24, 2017 23:56 — forked from shivkanthb/classify_startstop.py
Subscribe and unsubscribe to messages
from textblob.classifiers import NaiveBayesClassifier
from textblob import TextBlob
train = [
('Take me off', 'stop'),
('Stop texting','stop'),
('stop messaging','stop'),
('Don\'t talk', 'stop'),
('Stop messaging','stop'),
('dont want to talk anymore','stop'),