Skip to content

Instantly share code, notes, and snippets.

View seanbehan's full-sized avatar

Sean Behan seanbehan

View GitHub Profile
@seanbehan
seanbehan / filter-items-vanilla.html
Last active January 30, 2018 19:30
filter dom content with vanilla javascript js
<input type="text" onkeyup="filter(this)"/>
<div class="row">blah</div>
<div class="row">blah blah</div>
<div class="row">blah blah blah</div>
<script>
function filter(e){
search = e.value.toLowerCase();
document.querySelectorAll('.row').forEach(function(row){
text = row.innerText.toLowerCase();
@seanbehan
seanbehan / s3upload.bash
Last active December 29, 2017 00:52
Upload files to S3 via bash
#!/bin/sh
#
# Usage
# ./s3upload.bash path/to/file.txt name-of-file-on-s3.txt
#
file="$1"
path="$2"
key_id="s3 key goes here"
key_secret="s3 secret goes here"
bucket="bucket name goes here"
@seanbehan
seanbehan / youtube.bash
Last active May 12, 2020 04:09
Upload videos to Youtube.com with bash
#!/bin/sh
#
# Bash script for uploading videos to Youtube.com
#
# Usage:
# ./youtube.bash path-to-movie-movie.mov
#
# Setup
# Goto https://console.developers.google.com
# Create app, enable Youtube Data API and create OAuth credentials, client id and client secret.
//
// LoadingOverlay.swift
// app
//
// Created by Igor de Oliveira Sa on 25/03/15.
// Copyright (c) 2015 Igor de Oliveira Sa. All rights reserved.
//
// Usage:
//
// # Show Overlay
@seanbehan
seanbehan / django-base-model.py
Created July 25, 2017 00:42
Django BaseModel ORM __repr__ Example Custom JSONEncoder
import json, re
import dateparser
from django.db import models
from django.forms.models import model_to_dict
from uuid import uuid4, UUID
from datetime import date, datetime
from django.template.defaultfilters import slugify
class ModelEncoder(json.JSONEncoder):
def default(self, obj):
@seanbehan
seanbehan / app.py
Last active March 13, 2023 04:55
Flask with Django ORM
'''
Run the following commands (bc. gists don't allow directories)
pip install flask django dj-database-url psycopg2
mkdir -p app/migrations
touch app/__init__.py app/migrations/__init__.py
mv models.py app/
python manage.py makemigrations
python manage.py migrate
@seanbehan
seanbehan / slugify.py
Created February 23, 2017 01:43
python slugify a string
import re
text = ' asdfladf ljklasfj 2324@#$@#$@#43-----hi'
print re.sub(r'\W+', '-', text).strip('-')
@seanbehan
seanbehan / stopwords.txt
Last active February 15, 2017 01:30
english stop words
a
b
c
d
e
f
g
h
i
j
@seanbehan
seanbehan / app.py
Created October 16, 2016 19:48
using django-micro for small django sites
#
# pip install django-micro
#
# *make sure the label for model meta property is set to the name of current directory*
#
# python app.py makemigrations
# python app.py migrate
# python app.py runserver
#
import os
@seanbehan
seanbehan / user-lookup-address-and-timezone-from-google.rb
Created October 3, 2016 17:20
Lookup formatted address and timezone information with google webservices
require 'rest-client'
require 'json'
def lookup_address(address)
begin
address_data = JSON.parse(RestClient.get("https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=#{address}"))
address = address_data['results'][0]['formatted_address']
location = address_data['results'][0]['geometry']['location']
timezone_data = lookup_timezone("#{location['lat']},#{location['lng']}")