Skip to content

Instantly share code, notes, and snippets.

View erkarp's full-sized avatar
💭
* portraitist unknown

erkarp

💭
* portraitist unknown
View GitHub Profile
@erkarp
erkarp / camel_to_snake.py
Created March 22, 2019 15:16
Camel to snake converter
"""
Naive camel-to-snake converter
Assumes input to be valid camel case
"""
def camel_to_snake(text):
new_text = ''
for index in range(0, len(text)):
next_char = text[index]
@erkarp
erkarp / .bash_profile
Last active February 22, 2019 21:29
.bash_profile
alias refresh='. ~/.bash_profile'
alias bashx='nano ~/.bash_profile'
alias ll='ls -alh'
alias fork='open -a Fork .'
alias sa='cd /Users/ekarp/Development/sa'
alias cms='cd /Users/ekarp/Development/smartcms'
alias sam='cd /Users/ekarp/Development/smartadvisormatch'
alias branches='bash ~/branches.sh'
@erkarp
erkarp / branches.sh
Created May 31, 2018 18:20
git branch purge and display
#!/usr/bin/env bash
# Delete all merged branches
git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d;
# Display remaining branches
git for-each-ref --sort=-committerdate refs/heads/ --format='%(color:red)%(refname:short)|%(color:magenta)%(committerdate:relative)|%(color:blue)%(authorname)%(color:reset)|%(subject)' |
sed 's/refs\/heads\///g' |
grep -v BACKUP |
while IFS='|' read branch date author message
@erkarp
erkarp / capitalize.js
Created January 31, 2018 02:04
Capitalize each word in a string
const capitalize = originalSentence =>
{
return originalSentence.toLowerCase().split(' ').reduce((sentence, word) =>
{
let wordArray = word.split(/\b(\w)/);
if (wordArray.length)
{
wordArray[1] = wordArray[1].toUpperCase();
@erkarp
erkarp / .gitconfig
Last active May 9, 2018 18:19
git pretty
[alias]
last = show --stat --oneline
story = log --decorate --pretty=format:'%C(Yellow)%h%Creset %Cred%cd%Creset %Cblue%s%Creset%C(magenta)%d%Creset' --date=local
# These are also useful with --grep=<ticket number>
sa = log --decorate --pretty=format:'%C(Yellow)%h%Creset %<(15)%Cred%cd%Creset %<(17)%an %Cblue%s%Creset %C(magenta)%d%Creset' --date=relative --no-merges
rev = log --decorate --pretty=format:'%C(Yellow)%h%Creset %<(15)%Cred%cd%Creset %<(17)%an %Cblue%s%Creset %C(magenta)%d%Creset' --date=relative --no-merges --stat
code = log --decorate --pretty=format:'%C(Yellow)%h%Creset %<(15)%Cred%cd%Creset %<(17)%an %Cblue%s%Creset %C(magenta)%d%Creset' --date=relative --no-merges -p
# View local branches with extra info
@erkarp
erkarp / consoleTimer.js
Created January 30, 2018 15:33
JavaScript Console Timer
function createTimer() {
var start = (new Date()).valueOf()/1000;
return {
timestamp: function() {
var stamp = Math.floor((new Date()).valueOf()/1000 - start);
console.log('Timestamp:', stamp, 'seconds.', [].slice.call(arguments).join(' '));
}
}
@erkarp
erkarp / three-columns-wp-widget.php
Last active January 30, 2018 15:34
Basic WordPress widget to create a row with three resizable columns. Works best with Wing.
/**
* Class WPDocs_New_Widget
* https://github.com/KingPixil/wing/tree/master/src
*/
class Three_Columns extends WP_Widget {
function __construct() {
// Instantiate the parent object.
parent::__construct( false, __( 'Three Columns', 'textdomain' ), array(
// Chrome snippet to combine the text of short adjacent paragraphs
// for a more fluid reading experience
(function long() {
var paragraphs = document.getElementsByTagName('p');
for (var i=1; i<paragraphs.length; i++) {
var prev = paragraphs[i-1];
var pElem = paragraphs[i];
@erkarp
erkarp / resizeImage.scss
Last active January 30, 2018 22:05
Sass mixin to 'crop' an image with CSS clip-path
@mixin resizeImageY($x) {
width: 100%;
clip-path: inset(0 0 $x 0);
-webkit-clip-path: inset(0 0 $x 0);
margin-bottom: -$x;
}
@mixin resizeImageX($x) {
$half: $x/2;
clip-path: inset(0 $half+px 0 0);
@erkarp
erkarp / gitlog
Last active June 16, 2016 13:42
Bash functions to format git log
gitlog() {
c="git log --all --decorate --graph --pretty=format:%C(Yellow)%h%Creset_%Cred%cd%Creset_%Cblue%s%Creset%C(magenta)%d%Creset --date=local"
$c
}
# Use function 'datecode' (with optional date arg yyyy-mm-dd)
datestamp() {
date +"%Y-%m-%d"