This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var text = document.getElementById('#textForSpeech') | |
var msg = new SpeechSynthesisUtterance(text) | |
window.speechSynthesis.speak(msg) |
HTML for basic chat app
<div id="chat">
<div class="msg">
lorem...
</div>
<div class="msg">
lorem...
</div>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tab "The Title Goes Here" | |
tab() { | |
echo -ne "\033]0;$*\007" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"'}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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\.]+\$'; |