Skip to content

Instantly share code, notes, and snippets.

View seanbehan's full-sized avatar

Sean Behan seanbehan

View GitHub Profile
@seanbehan
seanbehan / ngram.rb
Created September 30, 2016 13:48
create ngrams in ruby
# Source https://snippets.aktagon.com/snippets/584-generating-word-n-grams-with-ruby
module Ngram
REGEX = /\w+/
def ngram_tokenize
self.downcase.scan(REGEX)
end
def ngram(n=1)
res = Set.new
words = ngram_tokenize
@seanbehan
seanbehan / text-to-speech.js
Created September 19, 2016 15:09
text to speech with JavaScript
var text = document.getElementById('#textForSpeech')
var msg = new SpeechSynthesisUtterance(text)
window.speechSynthesis.speak(msg)
@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 / invite.rb
Created June 12, 2016 18:10
rails message encryptor for invites
class Invite < ApplicationRecord
def self.enc
@enc ||= ActiveSupport::MessageEncryptor.new(ENV['ENC_SECRET'])
end
def token
class.enc.encrypt_and_sign(id.to_s)
end
def self.find_from_token(token)
@seanbehan
seanbehan / .bash_profile
Last active June 8, 2016 16:55
bash tab title
# tab "The Title Goes Here"
tab() {
echo -ne "\033]0;$*\007"
}
@seanbehan
seanbehan / flask-basic-auth.py
Created May 26, 2016 21:45
using basic auth in flask
Flask Basic Auth
@app.before_request
def basic_auth():
auth = request.authorization
if not auth or (auth.username != 'username' and auth.password != 'password'):
return response('Authentication required.', 401, {'WWW-Authenticate': 'Basic realm="Login Required"'})
@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 / upload-files-with-flask.md
Last active June 4, 2018 21:08
upload files to s3 with flask, PIL and tinys3

HTML form for file uploads

<!-- in templates/form.html -->
<form action="/upload" method="POST" enctype="multipart/form-data">
 <input type="file" name="logo">
 <button>Upload</button>
</form>
@seanbehan
seanbehan / postgres-find-float-rows.sql
Created May 10, 2016 15:03
find columns where the data is of float and non float type in postgres
-- grab columns where the value is float type
select * from table_name where column_name ~ E'^[0-9\.]+\$';
-- grab columns where the value is not float type
select * from table_name where column_name !~ E'^[0-9\.]+\$';