Skip to content

Instantly share code, notes, and snippets.

View TunedMystic's full-sized avatar

Sandeep Jadoonanan TunedMystic

View GitHub Profile
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

Is a useful one-liner which will give you the full directory name of the script no matter where it is being called from

These will work as long as the last component of the path used to find the script is not a symlink (directory links are OK). If you want to also resolve any links to the script itself, you need a multi-line solution:

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
@TunedMystic
TunedMystic / test.js
Created November 27, 2018 07:00 — forked from danmakenoise/test.js
Unit Testing Children of React Context API Consumers with Enzyme
// Component.js
const Component = props => (
<MyContext.Consumer>
{(context) => (
<Foo
bar={props.bar}
baz={context.baz}
/>
)}
</MyContext.Consumer>
@TunedMystic
TunedMystic / pagination_example.sql
Created September 10, 2018 01:59 — forked from ssokolow/pagination_example.sql
Reasonably efficient pagination without OFFSET (SQLite version)
-- Reasonably efficient pagination without OFFSET
-- SQLite version (Adapted from MS SQL syntax)
-- Source: http://www.phpbuilder.com/board/showpost.php?p=10376515&postcount=6
SELECT foo, bar, baz, quux FROM table
WHERE oid NOT IN ( SELECT oid FROM table
ORDER BY title ASC LIMIT 50 )
ORDER BY title ASC LIMIT 10
@TunedMystic
TunedMystic / curl.md
Created March 21, 2018 16:33 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@TunedMystic
TunedMystic / random_name_adj_noun.py
Created March 8, 2018 22:03
Generate a name from a random adjective and a random noun.
import random
adjectives = ['ashy', 'black', 'blue', 'gray', 'green', 'icy', 'lemon', 'mango', 'orange', 'purple', 'red', 'salmon', 'white', 'yellow', 'aggressive', 'agreeable', 'ambitious', 'brave', 'calm', 'delightful', 'eager', 'faithful', 'gentle', 'happy', 'jolly', 'kind', 'lively', 'nice', 'obedient', 'polite', 'proud', 'silly', 'thankful', 'victorious', 'witty', 'wonderful', 'zealousangry', 'bewildered', 'clumsy', 'defeated', 'embarrassed', 'fierce', 'grumpy', 'helpless', 'itchy', 'jealous', 'lazy', 'mysterious', 'nervous', 'obnoxious', 'panicky', 'pitiful', 'repulsive', 'scary', 'thoughtless', 'uptight', 'worried']
nouns = ['antelope', 'badger', 'mastif', 'bear', 'beaver', 'bobcat', 'chipmunk', 'coyote', 'deer', 'mule', 'elk', 'fox', 'gopher', 'lion', 'mouse', 'cactus', 'pinyon', 'pocket', 'muskrat', 'otter', 'porcupine', 'rabbit', 'cottontail', 'jack', 'raccoon', 'rat', 'kangaroo', 'pack', 'wood', 'ringtail', 'vagrant', 'skunk', 'hooded', 'striped', 'spotted', 'squirrel']
def random_name():
adj
@TunedMystic
TunedMystic / base_class_builder.py
Last active February 9, 2018 18:12
Dynamically inherit from other classes in Python
import datetime
import uuid
# -----------------------------------------------------
# Define all mixins here.
# -----------------------------------------------------
class APIMixin:
def __init__(self, *args, **kwargs):
print('[APIMixin] init')
@TunedMystic
TunedMystic / common_files.sh
Created February 5, 2018 20:06
Git: Identify commonly edited files
git log --pretty=format: --name-only | sort | uniq -c | sort -rg | head -10
@TunedMystic
TunedMystic / env_secrets_expand.sh
Last active January 25, 2018 22:41
Read docker secrets and export then to environment variables
ENV_SECRETS_DIR="/run/secrets"
env_secret_debug()
{
if [ ! -z "$ENV_SECRETS_DEBUG" ]; then
echo -e "\033[1m$@\033[0m"
fi
}
# usage: env_secret_expand VAR
@TunedMystic
TunedMystic / settings.py
Created January 10, 2018 19:03 — forked from ndarville/settings.py
Django on Travis CI
"""A basic database set-up for Travis CI.
The set-up uses the 'TRAVIS' (== True) environment variable on Travis
to detect the session, and changes the default database accordingly.
Be mindful of where you place this code, as you may accidentally
assign the default database to another configuration later in your code.
"""
import os
@TunedMystic
TunedMystic / gh-pages-deploy.md
Created May 28, 2017 03:27 — forked from cobyism/gh-pages-deploy.md
Deploy to `gh-pages` from a `dist` folder on the master branch. Useful for use with [yeoman](http://yeoman.io).

Deploying a subfolder to GitHub Pages

Sometimes you want to have a subdirectory on the master branch be the root directory of a repository’s gh-pages branch. This is useful for things like sites developed with Yeoman, or if you have a Jekyll site contained in the master branch alongside the rest of your code.

For the sake of this example, let’s pretend the subfolder containing your site is named dist.

Step 1

Remove the dist directory from the project’s .gitignore file (it’s ignored by default by Yeoman).