Skip to content

Instantly share code, notes, and snippets.

View ckalegi's full-sized avatar

Cameron Kalegi ckalegi

View GitHub Profile
@jbail
jbail / local-storage-with-json-parse-stringify.js
Created December 23, 2012 18:08
Local storage with JSON parse and stringify
var animal = {
name: 'Karl',
type: 'cat',
color: 'black',
age: 7
};
//convert JSON animal into a string
var dehydratedAnimal = JSON.stringify(animal);
@IngmarBoddington
IngmarBoddington / shellScripting
Last active February 14, 2022 17:23
Notes on shell scripting in Linux. Should be used in conjunction with terminal notes: https://gist.github.com/IngmarBoddington/4226355
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 $#
@indolering
indolering / transmission-vpn-launcher.applescript
Last active September 21, 2019 13:42
Uses Private Internet Access REST API to set which port Transmission listens on, binds all Transmission traffic to the tun0 (typically OpenVPN) network interface, and then opens Transmission.
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
@natelandau
natelandau / .bash_profile
Last active April 30, 2024 18:07
Mac OSX Bash Profile
# ---------------------------------------------------------------------------
#
# 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
@johndavidback
johndavidback / gist:fe17dc2a861fbf755691
Created July 17, 2014 14:38
Bootstrap Char Field for Django Form
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)
@bsweger
bsweger / useful_pandas_snippets.md
Last active April 19, 2024 18:04
Useful Pandas Snippets

Useful Pandas Snippets

A personal diary of DataFrame munging over the years.

Data Types and Conversion

Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)

@datchley
datchley / app.js
Last active September 20, 2022 01:22
"Getting Functional with Javascript" Blog post source files
/**
* 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
}
@jherax
jherax / filterArray.js
Last active February 23, 2024 12:59
Filters an array of objects with multiple match-criteria.
/**
* 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 => {
@akirattii
akirattii / background.js
Created December 2, 2016 03:45
Message passing of Chrome Extension example
/*****************************************************************
* 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 },