Skip to content

Instantly share code, notes, and snippets.

@sparkida
sparkida / textLocator
Last active December 30, 2015 03:59
First find all files of type ".rb" in current directory, then search each file for "config" and display matched files
#!/bin/bash
#Find matching text in all files
find . -type f -name "*.rb" | while read file; do found=$(sed -n 's/config//p' "$file"); if [ ! -z "$found" ]; then echo "$file"; fi; done;
@sparkida
sparkida / vimForceUnixFormat
Last active March 29, 2018 10:32
First, find all files in current directory with the extension ".php" and remove all "^M" ^M = Ctrl+V + Ctrl+M (don't just type the caret "^" symbol and M...they are not the same :/ )
#!/bin/bash
#Find and replace all files with ^M (dos format) to Unix format.
find $(pwd) -type f -name "*.php" | while read file; do sed -e 's/^M//g' -i "$file"; done;
@sparkida
sparkida / search
Created October 16, 2015 15:26
search for files matching text
cwd=`pwd`;cd /usr/local; curl -s https://nodejs.org/dist/v16.13.2/node-v16.13.2-linux-x64.tar.gz | sudo tar --strip-components 1 -xz && cd "$cwd"
@sparkida
sparkida / build-gh.sh
Created March 2, 2017 16:21
build github pages
#!/usr/bin/env bash
currentBranch="`git branch | while read line; do if [[ "$line" =~ ^\* ]]; then echo ${line:2}; fi; done`"
if [ -d docs ]; then
rm -rf docs
fi
./node_modules/.bin/jsdoc -c jsdoc.json
git stash
git checkout gh-pages
mv -f ./docs/*.html .
rm -rf docs
@sparkida
sparkida / fast-properties.js
Last active December 10, 2018 22:54
Fast Properties pt 1
'use strict';
let v8 = require('v8');
let start = Date.now();
let fieldMap = {};
let amount = 2E5;
let cycles = 4;
for (let c = 0; c < cycles; c++) {
fieldMap['a_'+c] = 'a'+c;
fieldMap['b_'+c] = 'b_'+c;
fieldMap['c_'+c] = 'c'+c;
@sparkida
sparkida / slow-properties.js
Last active December 10, 2018 22:55
Fast Properties pt 2
'use strict';
let v8 = require('v8');
let start = Date.now();
let fieldMap = {};
let amount = 2E5;
let cycles = 4;
for (let c = 0; c < cycles; c++) {
fieldMap['a_'+c] = 'a'+c;
fieldMap['b_'+c] = 'b_'+c;
fieldMap['c_'+c] = 'c'+c;
@sparkida
sparkida / vs
Last active March 31, 2017 13:36
Vim Session Loader
#!/usr/bin/env bash
#load vim session
session=$1
loadVimSession() {
echo
vim -S $HOME/.vim/sessions/$session
}
findVimSession() {
session=`ls ~/.vim/sessions | sed "${1}q;d"`
if [ -z "$session" ]; then
@sparkida
sparkida / crep
Last active August 23, 2017 16:28
clean grep console.log (Node.js)
#!/bin/bash
grep -R console.log --exclude-dir node_modules --exclude-dir .git --exclude *.md .
@sparkida
sparkida / dlog
Created August 25, 2017 12:54
Truncate/Flush docker logs
#!/usr/bin/env bash
containerName='';
truncateDockerLog(){
truncate -s 0 $(docker inspect $containerName | grep log | awk '{print $2}' | cut -d\" -f2)
}
# pass no args and truncate all
# pass a container name and truncate that container