Skip to content

Instantly share code, notes, and snippets.

View jstacoder's full-sized avatar
:octocat:
working

Kyle J. Roux jstacoder

:octocat:
working
View GitHub Profile
@jstacoder
jstacoder / EventStore.tsx
Last active June 12, 2023 11:53
useEventStore hook for calendar app
import React, {
createContext,
useReducer,
useContext,
} from 'react'
type Event = {
title: string;
start: string | Date;
end?: string | Date;
@jstacoder
jstacoder / validate.py
Last active May 16, 2019 13:48
VALIDATE QUICKBOOKS SIGNATURE HEADER FOR WEBHOOK PYTHON
import base64
import hmac
import hashlib
def validate_signature_header(verifier_token, request_body, signature):
# per quickbooks documentation
# 1st step:
# hash the notification payload (request_body) with HMAC_SHA256_ALGORITHM
# using <verifier token> as the key
hmac_hex_digest = hmac.new(
@jstacoder
jstacoder / ace_editor_field.py
Created April 25, 2017 23:11
ace editor field and widget class to use ace editor inside projects using wtforms
from wtforms import fields
class AceEditorWidget(object):
def __init__(self,mode='python',theme='twilight'):
self.theme = theme
self.mode = mode
self.custom_css = '<style>#editor { width: 100%; }</style>'
self.theme_js = 'editor.setTheme("ace/theme/{theme}");'.format(theme=self.theme)
self.mode_js = 'editor.setOption("mode","ace/mode/{mode}");'.format(mode=self.mode)
self.js = '''
@jstacoder
jstacoder / get_pdfs.py
Last active January 13, 2016 05:28
download files from it-ebooks.info, from the command line
# requires twill==0.9
import sys
from twill import get_browser
from pprint import pprint
class PdfFinder:
browser = None
_b = None
_q = None
links = {}
So22222222222222222222222222222o2SoSoeinSo22222*3oSoSo22222222222oSoSo2oSoSoSoSo
22222222o22222o2222o222221I*11I|I**Xl|+i**|I1i|+|II1*I12222oo2222oo222o2o222o2o2
22o22222o22222o2222o22222n||+|+|++||=|+|+|+=||+|+|+|+||*1o222222ooSo22o222222oSo
22o222o2o222o2oo2o2ooo*1||+|+|++|+|+|+|++|+||++|++|+|+|+|||I*2o22oo222oo22o2o2o2
22o22o22o22o22o22o*1|||+++|++|+|+|++|++|+|+++|+|+|+++|++|=|+||iooo222o2o2222o222
22222222o22222oeii||+|+|+|+|||+|++|+||+|+||||+||+|+||+|+|+|+||*Soo2222o222222o22
222o2222oSo222o1||++|+||||||||||||||||||||||||||||||||||++|++|+|*n2222oo2222o222
22oSoSo2o22221i|++|++|||||||||||||||||||||||||||||||||||||+|++|++|*So2o222222222
2ooooooooooeii||+|+|||||||i|i|i|||||||||||||||||||||i|||||||||++|iisvooooooooooo
22222222222ool=|++||||||>=::::::::+++++i|+++++++==;::=<||||||+|+|+i1222oSoS22222
@jstacoder
jstacoder / git_clone.py
Last active August 29, 2015 14:25
easily clone github repos
#!/usr/bin/env python
import commands
import sys
from functools import partial
CMD = 'git clone {protocol}{sep1}github.com{sep2}{user}/{repo}.git'
make_cmd = lambda **kwargs: CMD.format(**kwargs)
ssh = partial(make_cmd,protocol='git',sep1='@',sep2=':')
https = partial(make_cmd,protocol='https',sep1='://',sep2='/')
@jstacoder
jstacoder / alert.html
Last active April 13, 2018 02:55
example of integrating mongoengine with flask
{% for cat,msg in get_flashed_messages(with_categories=true) %}
<div class="alert alert-dissmissable alert-{{ cat }}" id="alert-{{ loop.index }}">
<span id="close-alert-{{ loop.index }}" class=close>x</span>
{{ msg }}
</div>
<script>
var alert = document.getElementById('alert-{{ loop.index }}'),
closeBtn = document.getElementById('close-alert-{{ loop.index }}');
closeBtn.onClick = function(){
alert.remove();
@jstacoder
jstacoder / _tables.py
Last active February 10, 2017 23:53
fun with python lambdas, print database tables and columns with a single line function using lambdas and sqlalchemy
print_tables =\
lambda\
BaseModel:\
''.join(
map(
lambda x:\
'\n{}\n{}\n'.format(
x[0],
x[1].__table__.c.keys()
),filter(
@jstacoder
jstacoder / angularapp.py
Last active June 1, 2023 11:14
flask / angular example (underscores in filenames mean directorys)
from flask import Flask
from flask import render_template
app = Flask(__name__)
app.url_map.strict_slashes = False
@app.route('/partials/<partial>')
def partial(partial):
return render_template(partial,jinja_var='this is from jinja')
@jstacoder
jstacoder / manage.py
Created January 14, 2015 04:13
flask_script - gather_templates command (like djangos management command, but for flask)
from flask import Flask
from flask_script import Manager
from flask_admin import Admin
import os.path as op
import os
app = Flask(__name__)
manager = Manager(app)
admin = Admin(app) #<-- this gives our app some templates to gather