Skip to content

Instantly share code, notes, and snippets.

View jhargis's full-sized avatar

Jay Hargis jhargis

  • Heroku
  • Portland, OR
View GitHub Profile
@jhargis
jhargis / js_barcode_scanner.js
Last active October 20, 2022 02:37
javascript barcode scanner
document.addEventListener('DOMContentLoaded', function () {
if(!window.hasOwnProperty('scan_data')) {
window.scan_data = [];
window.scan_prefix_target = null;
}
// keystroke speed < 80ms & min total length of 4 chars
const scan_min_chars = 4, scan_keystroke_window_ms = 80;
let _scan_timer = window.setTimeout(function() { window.scan_data = []; }, 0);
@jhargis
jhargis / bottle_flash2.py
Last active June 20, 2021 21:09
bottle-flash2 - Fixed up abandoned bottle-flash[https://pypi.python.org/pypi/bottle-flash/]. Made api ver 2 ready. Plugin enables flash messages in bottle similar to django and flask.
from bottle import request, response, PluginError
class FlashMsgPlugin(object):
"""Usage:
from bottle import Bottle
from bottle_flash2 import FlashMsgPlugin
app = Bottle()
COOKIE_SECRET = 'your_secret_key'
app.install(FlashPlugin(secret=COOKIE_SECRET))
@jhargis
jhargis / PrivateTorrent.md
Created March 12, 2021 01:40 — forked from sourcec0de/PrivateTorrent.md
Host a private torrent tracker, and seed a torrent on ubuntu 12.10

Install dep, and start tracker

sudo apt-get install bittornado ctorrent
bttrack --port 6969 --dfile ~/.bttrack/dstate --logfile ~/.bttrack/tracker.log --nat_check 0 --scrape_allowed full

Now, create a torrent file

ctorrent -t -u "YOUR_SERVER_IP:6969/announce" -s new_file_name.torrent file_or_folder_for_torrent
@jhargis
jhargis / plot.awk
Created October 19, 2020 19:04 — forked from katef/plot.awk
#!/usr/bin/awk -f
# This program is a copy of guff, a plot device. https://github.com/silentbicycle/guff
# My copy here is written in awk instead of C, has no compelling benefit.
# Public domain. @thingskatedid
# Run as awk -v x=xyz ... or env variables for stuff?
# Assumptions: the data is evenly spaced along the x-axis
# TODO: moving average
@jhargis
jhargis / pull-toggl-timesheet.py
Last active March 2, 2020 20:43
Python based timesheet report generation utility for toggl.com api This generates CSV and HTML files from an api call filtered on client and date range.
#!/usr/bin/env python
import os
import csv
import sys
import datetime
import string
import requests
# replace these: API_KEY, CLIENTNAME1, CLIENTNAME2 , CLIENT_ID1, CLIENT_ID2 , WORKSPACE_ID
#! /usr/bin/env python3
'''pyCookieCheat.py
2015022 Now its own GitHub repo, and in PyPi.
- For most recent version: https://github.com/n8henrie/pycookiecheat
- This gist unlikely to be maintained further for that reason.
20150221 v2.0.1: Now should find cookies for base domain and all subs.
20140518 v2.0: Now works with Chrome's new encrypted cookies.
See relevant post at http://n8h.me/HufI1w
@jhargis
jhargis / postgres_queries_and_commands.sql
Created August 9, 2019 17:42 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@jhargis
jhargis / __init__.py
Last active November 18, 2018 22:00
using jinja2 with cherrypy - example
# -*- coding: utf-8 -*-
# http://docs.cherrypy.org/en/latest/advanced.html?highlight=jinja2#html-templating-support
import os.path
import cherrypy
class Root(object):
@cherrypy.expose
def index(self):
@jhargis
jhargis / remove_table_bloat_async_with_inheritance.md
Last active August 24, 2018 19:35 — forked from mage2k/gist:747674bb8a1a970007952adc283a857c
Trick for removing table bloat without requiring a full table lock and production halt

Given a table bar that we need to compact while maximizing availability of the data in it and minimize load/IO during compaction.

First, if there are any tables with foriegn key columns referencing columns in bar those foreign keys need to be disabled, e.g:

ALTER TABLE foo DISABLE TRIGGER fkey_bar_id

Now we can work on compacting the data by copying it to a new table.

SQL to create a new, empty table and have the current table inherit from it:

@jhargis
jhargis / django_bulk_export.py
Last active June 13, 2018 17:43
django and psycopg2 with server side cursors for memory efficient large bulk data exports
import uuid
import psycopg2
from psycopg2.extras import DictCursor
from django.conf import settings
from django.db import models
from django.contrib.auth.models import User
class classproperty(object):