This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count_file_iter(*ar, **kw): | |
""" | |
Small utility to iterate through individual rows of a file given a generator, | |
used only to count rows. | |
:param ar: args for open() | |
:param kw: keyword args for open() | |
:return: yields 1 for each row | |
""" | |
for _ in open(*ar, **kw): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def readable_size(byte_size: int, base: int = 10, decimals: int = 1): | |
""" | |
Given the size of an object in bytes, returns a human-readable alternative. | |
For ex: | |
>>> readable_size(44000000) | |
42.0 MB | |
Supports sizes up to 1024 yobibytes in Binary or 1000 yottabytes in Decimal SI. | |
Inspired by the following StackOverflow questions: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import networkx as nx | |
from string import ascii_lowercase, digits | |
COLW = 10 | |
chars = ascii_lowercase + digits |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In 000's | |
pv = 400 | |
savings_rate = 0.10 | |
ir = 0.025 | |
periodicity = 4 | |
years = 20 | |
cf = pv * savings_rate | |
nper = periodicity * years | |
irper = ir / periodicity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$number-of-steps: 6; | |
.stage { | |
// etc. | |
&.active { | |
// Accents current stage's title. | |
.stage-title { | |
-webkit-box-shadow:-2px 2px 5px -1px darken($brand-blue,11%) inset; | |
-moz-box-shadow:-2px 2px 5px -1px darken($brand-blue,11%) inset; | |
box-shadow:-2px 2px 5px -1px darken($brand-blue,11%) inset; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
preventAlerts: function () { | |
//Copy drupal's original error function for later use if you want | |
Drupal.ajax.prototype.original_error = Drupal.ajax.prototype.error; | |
Drupal.ajax.prototype.error = function (response, uri) { | |
// This should catch the "terminated abnormally" error | |
if (response.readyState == 0 || response.readyState == 4) { | |
console.log(response); | |
} | |
else { | |
this.original_error(response, uri); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_gitff() { | |
REMOTES="$@"; | |
if [ -z "$REMOTES" ]; then | |
REMOTES=$(git remote); | |
fi | |
REMOTES=$(echo "$REMOTES" | xargs -n1 echo) | |
CLB=$(git branch -l|awk '/^\*/{print $2}'); | |
echo "$REMOTES" | while read REMOTE; do | |
git remote update $REMOTE | |
git remote show $REMOTE -n \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@mixin triangle($direction: "right", $size: 5px, $color: '#FFFFFF') { | |
@if not index(top right bottom left, $direction) { | |
@warn "\"#{$direction}\" is not a valid direction value. Value must be one of: top, right, bottom, left"; | |
} | |
@else { | |
@include transform(scale(1.01)); // @see https://brettstrikesback.com/de-pixelating-the-css-triangle/ | |
border: $size solid transparent; | |
border-#{$direction}-color: $color; | |
border-#{opposite-position($direction)}-width: 0; | |
#{opposite-position($direction)}: -$size; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).on({ | |
mouseenter: function (evt) { | |
$(evt.target).data('hovering', true); | |
}, | |
mouseleave: function (evt) { | |
$(evt.target).data('hovering', false); | |
} | |
}, "*"); | |
jQuery.expr[":"].hovering = function (elem) { | |
return $(elem).data('hovering') ? true : false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Shortened drush sql-sync; drops all tables of destination environment, | |
# then syncs a non-cached version of the source environment | |
_dss () { | |
local timestamp=$(date "+%Y%m%d-%H%M%S") | |
local site=${1//[@]/} | |
local source=${2:-prod} | |
local dest=${3:-local} | |
if [ -z "$4" ]; then dump_path=../..; else dump_path=$4; fi | |
time { |
NewerOlder