Skip to content

Instantly share code, notes, and snippets.

@jacqueswww
jacqueswww / yaml.vim
Created October 25, 2015 12:00 — forked from iangreenleaf/yaml.vim
Dumb-smart indentation for Yaml
" Vim indent file
" Language: Yaml
" Author: Ian Young
" Get it bundled for pathogen: https://github.com/avakhov/vim-yaml
if exists("b:did_indent")
finish
endif
"runtime! indent/ruby.vim
"unlet! b:did_indent
@jacqueswww
jacqueswww / ubuntu_ansible_bootstrap.sh
Last active November 19, 2015 22:23
Ansible bootstrap
#!/bin/bash
# bootstrap a container to accept ansible.
key_location="https://github.com/jacqueswww.keys"
sudo apt-get install -y curl python
sudo mkdir /root/.ssh/
sudo chmod 600 /root/.ssh/
sudo curl $key_location > /root/.ssh/authorized_keys
#!/bin/bash
sudo apt-get install openjdk-7-jre
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
sudo echo "deb http://packages.elastic.co/elasticsearch/2.x/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-2.x.list
sudo apt-get update && sudo apt-get install elasticsearch
sudo update-rc.d elasticsearch defaults 95 10
sudo service elasticsearch start
@jacqueswww
jacqueswww / detect_ip_address.py
Created January 16, 2016 21:09
Detect an ip address
import sys
def ipv6(s):
group_split = s.split(':')
if len(group_split) == 8:
for sub in group_split:
try:
ip_val = int(sub, 16)
if 0 <= ip_val <= 65535:
continue
@jacqueswww
jacqueswww / watch-test.sh
Last active May 9, 2016 07:04
Run tests on changes.
#!/bin/bash
TEST_COMMAND="python manage.py test --keepdb --no-input --failfast "$1
$TEST_COMMAND
while find ./ -name '*.py' | inotifywait --fromfile - -e modify;
do
$TEST_COMMAND
done
@jacqueswww
jacqueswww / dict_contains.py
Created May 25, 2016 12:54
One dictionary exists in another
def dict_contains(primary, secondary):
"""
Does primary dict contains all the same items as secondary.
"""
assert isinstance(primary, dict)
assert isinstance(secondary, dict)
for key, val in secondary.items():
@jacqueswww
jacqueswww / gist:5ba0ac7e27f7b05ad859d0428e5c4177
Created August 24, 2016 17:05 — forked from nealtodd/gist:a8f87b0d95e73eb482c5
Django management command to detect missing migration files.
import sys
from django.apps import apps
from django.conf import settings
from django.core.management.base import BaseCommand
from django.db import connections
from django.db.migrations.autodetector import MigrationAutodetector
from django.db.migrations.executor import MigrationExecutor
from django.db.migrations.state import ProjectState
from django.db.utils import OperationalError
@jacqueswww
jacqueswww / get_filefield_models.py
Created January 13, 2017 13:05
Get all django models with FielFields attached to them.
from django.apps import apps
def get_models_with_file_fields():
for model in apps.get_models():
if any(field.__class__.__name__ in ('FileField', 'ImageField')
for field in model._meta.fields):
print(model)
@jacqueswww
jacqueswww / memory_usage.py
Created February 3, 2017 13:26
Quickly see memory usage from within a python process (Linux only)
import os
class MemoryUsage:
# thanks to http://code.activestate.com/recipes/286222/
def __init__(self):
self._proc_status = '/proc/%d/status' % os.getpid()
self._scale = {
'kB': 1024.0, 'mB': 1024.0 * 1024.0,
@jacqueswww
jacqueswww / my_token.v.py
Last active September 9, 2017 14:48
Attempt at translating MyToken example to viper.
# Viper Port of MyToken
# Originally found at https://www.ethereum.org/token
# Public variables of the token
name: public(bytes32)
symbol: public(bytes32)
totalSupply: public(num)
decimals: public(num)
balanceOf: public(num256[address])