Skip to content

Instantly share code, notes, and snippets.

View seanbehan's full-sized avatar

Sean Behan seanbehan

View GitHub Profile
@seanbehan
seanbehan / flask-mailer.py
Created May 23, 2016 19:13
generate signed token for email confirmation with python and flask
from itsdangerous import URLSafeTimedSerializer
from project import app
def generate_confirmation_token(email):
serializer = URLSafeTimedSerializer(app.config['SECRET_KEY'])
return serializer.dumps(email, salt=app.config['SECURITY_PASSWORD_SALT'])
@seanbehan
seanbehan / sample-html-css-js-for-chat.md
Created June 13, 2016 15:37
sample html, css and javascript for base chat app

HTML for basic chat app

<div id="chat">
  <div class="msg">
    lorem...
    </div>
  <div class="msg">
    lorem...
  </div>
@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 / clear-sidekiq-jobs.sh
Created January 28, 2023 15:58 — forked from wbotelhos/clear-sidekiq-jobs.sh
Clear Sidekiq Jobs
require 'sidekiq/api'
# 1. Clear retry set
Sidekiq::RetrySet.new.clear
# 2. Clear scheduled jobs
Sidekiq::ScheduledSet.new.clear
@seanbehan
seanbehan / poker_combo_ranks.csv
Created January 6, 2023 04:57
Poker combo ranks
rank combo
1 AA
2 KK
3 QQ
4 AKs
5 JJ
6 AQs
7 KQs
8 AJs
9 KJs
.aaa
.aarp
.abarth
.abb
.abbott
.abbvie
.abc
.able
.abogado
.abudhabi
@seanbehan
seanbehan / bulk-upsert-from-temporary-table.sql
Created October 17, 2015 16:49
Perform an "upsert" from CSV file using Postgres copy command #sql #psql
create temporary table temp (symbol varchar(255), open decimal, high decimal, low decimal, close decimal, volume varchar(255), date date );
create table if not exists stocks (id serial primary key, symbol varchar(255), open decimal, high decimal, low decimal, close decimal, volume varchar(255), date date, created_at timestamp, updated_at timestamp);
copy temp (symbol, date, open, high, low, close, volume) from '/path/to/file.csv' with delimiter ',' csv header;
delete from stocks using temp where stocks.date = temp.date and stocks.symbol = temp.symbol;
insert into stocks (symbol, open, high, low, close, volume, date) select symbol, open, high, low, close, volume, date from temp;
@seanbehan
seanbehan / app.py
Last active November 20, 2022 17:31
Create a multi site Flask application using Blueprints. This app will match hostname to serve a distinct application.
# set up /etc/hosts
# 127.0.0.1 site1.loc site2.loc
from flask import (
Flask
)
import site1, site2
app = Flask(__name__)
@seanbehan
seanbehan / gist:2935f8b4df956f8693eabdc5c715a526
Created November 15, 2022 02:18 — forked from ekayxu/gist:5743138
Make Flask support regular expressions in its URL routing
#http://stackoverflow.com/questions/5870188/does-flask-support-regular-expressions-in-its-url-routing
#Even though Armin beat me to the punch with an accepted answer I thought I'd show an abbreviated example of how I implemented a regex matcher in Flask just in case anyone wants a working example of how this could be done.
from flask import Flask
from werkzeug.routing import BaseConverter
app = Flask(__name__)
class RegexConverter(BaseConverter):
def __init__(self, url_map, *items):
@seanbehan
seanbehan / email-regex-match.js
Last active October 3, 2022 07:49
extract email addresses from string with javascript
// http://rubular.com/r/twBPG8HQgP
regex = /\S+[a-z0-9]@[a-z0-9\.]+/img
"hello sean@example.com how are you? do you know bob@example.com?".match(regex)
// ["sean@example.com", "bob@example.com"]