Skip to content

Instantly share code, notes, and snippets.

View theY4Kman's full-sized avatar

Zach Kanzler theY4Kman

View GitHub Profile
@jeremyBanks
jeremyBanks / expanded.md
Created June 22, 2010 05:10
one-line self-executing c header and expanded explanation
//

Since we don't want this visible in C, we put it in a comment.

&>/dev/null

Unfortunately // is interpreted as an invalid shell command and produces an error message, so we need to redirect that to /dev/null to get rid of it.

;x="${0%.*}"
@avidal
avidal / get_permissions.py
Created January 14, 2011 21:26
This snippet will get all permission objects for a specific model.
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from myapp.models import MyModel
content_type = ContentType.objects.get_for_model(MyModel)
permissions = Permission.objects.filter(content_type=content_type)
@jtriley
jtriley / terminalsize.py
Created July 26, 2011 21:58
Get current terminal size on Linux, Mac, and Windows
#!/usr/bin/env python
import os
import shlex
import struct
import platform
import subprocess
def get_terminal_size():
""" getTerminalSize()
@timoxley
timoxley / gist:1721593
Created February 2, 2012 04:58
Recursively run all tests in test directory using mocha
// this will find all files ending with _test.js and run them with Mocha. Put this in your package.json
"scripts": {
"test": "find ./tests -name '*_test.js' | xargs mocha -R spec"
},
@mshafrir
mshafrir / states_hash.json
Created May 9, 2012 17:05
US states in JSON form
{
"AL": "Alabama",
"AK": "Alaska",
"AS": "American Samoa",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active May 22, 2024 05:53
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%'
@theY4Kman
theY4Kman / gist:7760149
Last active August 11, 2016 18:45
Decorator to automatically create a keyword-discriminating autouse fixture, so you can use either @pytest.mark.xxxx or shove in xxxx as an argument in order to use it. This way you don't have to make things arguments that aren't really arguments, and you need not rely on boilerplate usefixtures calls. You know what the mark means.
def _keyword_fixture(fn):
fixture_name = fn.__name__
fixture_module = import_module(fn.__module__)
@pytest.fixture(autouse=True)
def _autouse_fixture(request):
if fixture_name in request.keywords:
request.getfuncargvalue(fixture_name)
_autouse_fixture.__name__ = '_{}_autouse'.format(fixture_name)
@hexsprite
hexsprite / ignore_warning.py
Created July 3, 2014 17:24
Python: ignore specific warning using context manager
import warnings
def fxn():
warnings.warn("deprecated", DeprecationWarning)
with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=DeprecationWarning)
fxn()
@jordan-brough
jordan-brough / git-recent
Last active April 8, 2024 02:53
Git: Display a list of recently checked out branches/tags/commits
#!/usr/bin/env bash
# Source: https://gist.github.com/jordan-brough/48e2803c0ffa6dc2e0bd
# See also: https://stackoverflow.com/a/25095062/58876
# Download this script as "git-recent" (no extension), chmod it to be executable and put it in your
# path somewhere (e.g. /usr/bin). You can then use it via `git recent` from inside any git repo.
# Examples:
@n3dst4
n3dst4 / ConEmu Git Bash.md
Last active July 19, 2022 17:11
My ConEmu / Cmder git bash task config
  1. Open Conemu

  2. Open Settings -> Tasks or go to new tab button -> Setup tasks.

  3. Click + to add a new task

  4. Enter the name as Git Bash or whatever you like

  5. Task parameters:

     /icon "C:\Program Files (x86)\Git\etc\git.ico" /dir "C:\_git"
    
  6. Command: