Skip to content

Instantly share code, notes, and snippets.

@drkdelaney
drkdelaney / empty_files.py
Created May 17, 2018 15:42
Prints out the directory of an empty file in a given root directory
import os
import sys
import argparse
def empty_files(rootdir):
for subdir, dirs, files in os.walk(rootdir):
for file in files:
if os.path.getsize(os.path.join(subdir, file)) == 0:
print os.path.join(subdir, file)
@drkdelaney
drkdelaney / no_spec_file.py
Last active May 16, 2018 21:31
Prints the directory if there is a missing spec file for javascript. Use `--exclusions` to ignore keywords in a file name.
import os
import sys
import argparse
def no_spec_file(rootdir, exclusions):
for subdir, dirs, files in os.walk(rootdir):
for file in files:
split_file = os.path.join(subdir, file).split('.')
if len(split_file) == 2 and split_file[1] == 'js':
spec_file = split_file[0]+'.spec.js'
@drkdelaney
drkdelaney / difference.js
Created April 16, 2018 22:44 — forked from Yimiprod/difference.js
Deep diff between two object, using lodash
/**
* Deep diff between two object, using lodash
* @param {Object} object Object compared
* @param {Object} base Object to compare with
* @return {Object} Return a new object who represent the diff
*/
function difference(object, base) {
function changes(object, base) {
return _.transform(object, function(result, value, key) {
if (!_.isEqual(value, base[key])) {

VSCode

Settings

  • enable emmet on tab
  • enable emmet in JSX
  • enable font ligatures
  • use Firacode font
  • open external terminal
  • setting sync
@drkdelaney
drkdelaney / text_replace.py
Created January 24, 2018 18:47
finds and replaces text in a file
#!/usr/bin/env python3
from __future__ import print_function
from contextlib import closing
import os
import sys
import argparse
import fileinput
def text_replace(fileToSearch, textToSearch, textToReplace):
with closing(fileinput.FileInput(fileToSearch, inplace=True, backup='.bak')) as file:
@drkdelaney
drkdelaney / s3_uploader.py
Last active May 16, 2018 19:03
uploads files and folders to an s3 bucket
from __future__ import print_function
import os
import sys
import argparse
import boto3
from botocore.exceptions import ClientError
def upload_to_s3(bucket, artefact, is_folder, bucket_key):
"""
Uploads an artefact to Amazon S3
@drkdelaney
drkdelaney / s3_upload.js
Last active January 17, 2018 03:23
Uploads a folder and its content to an s3 bucket
/**
* Get variables from command line
*/
let cmd = {};
let args = ['command', 'file', 'bucket', 'src']
process.argv.forEach(function(val, index, array) {
if (array.length === 4) {
cmd[args[index]] = val;
}
});
@drkdelaney
drkdelaney / zip.py
Created January 12, 2018 23:12
zip a folder
# zips a folder
import os
import sys
import argparse
import zipfile
def zip(src, dst):
fname = "%s.zip" % (dst)
if os.path.exists(fname):
@drkdelaney
drkdelaney / lodashGetAlternative.js
Created November 27, 2017 16:46 — forked from jeneg/lodashGetAlternative.js
Alternative to lodash get method _.get()
function get(obj, path, def) {
var fullPath = path
.replace(/\[/g, '.')
.replace(/]/g, '')
.split('.')
.filter(Boolean);
return fullPath.every(everyFunc) ? obj : def;
function everyFunc(step) {
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// add additional config below
summon: {
hotkey: 'Alt+Space'