A personal diary of DataFrame munging over the years.
Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)
var animal = { | |
name: 'Karl', | |
type: 'cat', | |
color: 'black', | |
age: 7 | |
}; | |
//convert JSON animal into a string | |
var dehydratedAnimal = JSON.stringify(animal); |
Basics | |
====== | |
Expansion (special symbols replaced by values) and word splitting (arguments being split into several aruments) must have attemtion paid or pain will follow. | |
- # for comments | |
- Lots of internal variables available to bash scripts, see: http://tldp.org/LDP/abs/html/internalvariables.html#ARGLIST | |
- Name of script will be $0 | |
- Parameters passed to script will be in $1, $2, $3.... vars and count in $# |
set user to "USERNAME" | |
set pass to "PASSWORD" | |
--set token automatically based on macaddress | |
set macAddHash to do shell script "/sbin/ifconfig en0 | /usr/bin/awk '/ether / {print $2}' | /usr/bin/tr -d ':' | md5 " | |
try | |
set vpn_ip to do shell script "ifconfig tun0 | grep inet | awk '{print $2}'" | |
--hack: must delete property before writing it but first run 'defaults delete' fails |
# --------------------------------------------------------------------------- | |
# | |
# Description: This file holds all my BASH configurations and aliases | |
# | |
# Sections: | |
# 1. Environment Configuration | |
# 2. Make Terminal Better (remapping defaults and adding functionality) | |
# 3. File and Folder Management | |
# 4. Searching | |
# 5. Process Management |
from django import forms | |
class BootstrapCharField(forms.CharField): | |
def __init__(self, *args, **kwargs): | |
# Grab the placeholder from the kwargs if it exists | |
placeholder = kwargs.pop('placeholder') if 'placeholder' in kwargs else u'' | |
# Build all the defaults | |
super(BootstrapCharField, self).__init__(*args, **kwargs) |
A personal diary of DataFrame munging over the years.
Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)
/** | |
* Primary application logic for our Functional Programming blog example | |
* See related blog series at: http://www.datchley.name/tag/functional-programming/ | |
* Version: 2.0 | |
*/ | |
// A simple, resuable comparison for '>=' | |
function greaterThanOrEqual(a, b) { | |
return a >= b | |
} |
/** | |
* Filters an array of objects using custom predicates. | |
* | |
* @param {Array} array: the array to filter | |
* @param {Object} filters: an object with the filter criteria | |
* @return {Array} | |
*/ | |
function filterArray(array, filters) { | |
const filterKeys = Object.keys(filters); | |
return array.filter(item => { |
/***************************************************************** | |
* onMessage from the extension or tab (a content script) | |
*****************************************************************/ | |
chrome.runtime.onMessage.addListener( | |
function(request, sender, sendResponse) { | |
if (request.cmd == "any command") { | |
sendResponse({ result: "any response from background" }); | |
} else { | |
sendResponse({ result: "error", message: `Invalid 'cmd'` }); | |
} |
const countryCodes = { | |
US: 'United States', | |
CA: 'Canada', | |
NG: 'Nigeria', | |
GB: 'United Kingdom', | |
}; | |
const sales = [ | |
{ code: 'US', count: 233 }, |