Skip to content

Instantly share code, notes, and snippets.

View dhrrgn's full-sized avatar
🦙

Dan Horrigan dhrrgn

🦙
  • OH, USA
  • 16:39 (UTC -04:00)
View GitHub Profile
@dhrrgn
dhrrgn / debug_stuff.py
Last active January 28, 2024 21:25
A handy SQL debug function for Flask-SQLAlchemy
from . import app
from flask.ext.sqlalchemy import get_debug_queries
if app.debug:
app.after_request(sql_debug)
def sql_debug(response):
queries = list(get_debug_queries())
query_str = ''
<div class="_li">
<div id="pagelet_bluebar" data-referrer="pagelet_bluebar">
<div id="blueBarDOMInspector" class="_21dp">
<div class="_2t-8 _1s4v _2s1x">
<div class="_2t-a _26aw _50ti _2s1y" role="banner">
<div class="_2t-a _50tj">
<div class="_2t-a _4pmj _2t-d _50tk"><a class="accessible_elem skipto" href="#newsFeedHeading" target="newsFeedHeading" id="u_0_0">Skip to News Feed</a>
<div class="_2t-e">
<div class="_4kny">
<h1 class="_19ea" data-click="bluebar_logo"><a class="_19eb" data-gt="&#123;&quot;chrome_nav_item&quot;:&quot;logo_chrome&quot;&#125;" href="https://www.facebook.com/?ref=logo"><span class="_2md">Facebook</span></a></h1>

Configure

xdebug.ini

xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
@dhrrgn
dhrrgn / sitemap.xml
Last active April 11, 2023 07:23
sitemap.xml
<?xml version="1.0" encoding="utf-8"?><sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>http://www.amazon.com/sitemaps.f3053414d236e84.US_detail_page_sitemap_desktop_2014-03-22_107_0_0.xml.gz</loc>
</sitemap>
<sitemap>
<loc>http://www.amazon.com/sitemaps.f3053414d236e84.US_detail_page_sitemap_desktop_2014-03-22_107_100_0.xml.gz</loc>
</sitemap>
<sitemap>
<loc>http://www.amazon.com/sitemaps.f3053414d236e84.US_detail_page_sitemap_desktop_2014-03-22_107_101_0.xml.gz</loc>
</sitemap>
@dhrrgn
dhrrgn / index.html
Created August 20, 2022 14:45
Llamaly Landing
<div><img src="https://llamaly-assets.s3.us-east-2.amazonaws.com/images/logo-large.jpg" /></div>
@dhrrgn
dhrrgn / formatters.py
Last active April 6, 2022 19:51
Python timedelta object formatting for humans.
def human_delta(tdelta):
"""
Takes a timedelta object and formats it for humans.
Usage:
# 149 day(s) 8 hr(s) 36 min 19 sec
print human_delta(datetime(2014, 3, 30) - datetime.now())
Example Results:
23 sec
@dhrrgn
dhrrgn / functions.php
Created March 3, 2014 16:02
Slugify. Note: Requires PHP >= 5.4 and the Intl extension
<?php
function slugify($string, $toLower = true) {
$rules = "Any-Latin; Latin-ASCII; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove;";
if ($toLower) {
$rules .= ' Lower();';
}
$string = transliterator_transliterate($rules, $string);
// Remove repeating hyphens and spaces (e.g. 'foo---bar' becomes 'foo-bar')
@dhrrgn
dhrrgn / core.py
Last active March 2, 2022 04:16
Tired of doing db.session.add and db.session.commit to save your records? Have no fear, save is here. Note: This is for use with Flask-SQLAlchemy
from .user import User
def init_db(db):
"""Add a save() function to db.Model"""
def save(model):
db.session.add(model)
db.session.commit()
db.Model.save = save
@dhrrgn
dhrrgn / RedisSession.php
Last active February 15, 2022 19:54
PHP 5.4 Redis Session Handler
<?php
use Predis\Client;
class RedisSession implements SessionHandlerInterface {
private $redis;
private $keyPrefix;
private $maxLifetime;
/**
@dhrrgn
dhrrgn / typecheck.php
Last active January 14, 2022 11:53
PHP Type Check Function
<?php
/**
* Checks the type of the given value against an array of valid types.
*
* If the value is a valid type, `true` is returned, if not, an
* InvalidArgumentException is thrown.
*
* // Throws: Invalid type: string, Expected type(s): array, ArrayAccess
* checktype('foo', ['array', 'ArrayAccess']);