Skip to content

Instantly share code, notes, and snippets.

Avatar

Guy Arad guyarad

View GitHub Profile
@guyarad
guyarad / fix_onedrive.sh
Created Nov 9, 2020 — forked from drblue/fix_onedrive.sh
Fix OneDrive for Mac CPU usage
View fix_onedrive.sh
#!/bin/bash
## Fix OneDrive for Mac CPU usage
##
## Seems this is still a problem 5 years later after I created this little gist.
## I have long since stopped using OneDrive (luckily), but according to
## comments below, I have added the new path for OfficeFileCache for macOS
## Mojave (10.14) and Catalina (10.15).
## Run this on macOS Mojave (10.14) and Catalina (10.15)
find ~/Library/Containers/ -type d -name OfficeFileCache -exec rm -r {} +
@guyarad
guyarad / Makefile
Created Oct 5, 2020 — forked from mpneuried/Makefile
Simple Makefile to build, run, tag and publish a docker containier to AWS-ECR
View Makefile
# import config.
# You can change the default config with `make cnf="config_special.env" build`
cnf ?= config.env
include $(cnf)
export $(shell sed 's/=.*//' $(cnf))
# import deploy config
# You can change the default deploy config with `make cnf="deploy_special.env" release`
dpl ?= deploy.env
include $(dpl)
@guyarad
guyarad / csv2table.py
Created Aug 4, 2020 — forked from caiosba/csv2table.py
Python script to convert from CSV to a pretty ASCii table
View csv2table.py
#!/usr/bin/python
from __future__ import print_function
import prettytable
import csv
import sys
def main(argv):
if len(sys.argv) != 3:
print('Usage: python csv2table.py [input file] [output]\n')
View hitech_problems_email_sender.py
# -*- coding: utf-8 -*-
#use python3 (tested on 3.7)
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import formatdate
@guyarad
guyarad / build.sh
Created Nov 26, 2019 — forked from lucasea777/build.sh
Python C Extension Hello World
View build.sh
gcc -fpic --shared $(python3-config --includes) greetmodule.c -o greet.abi3.so
# can also use $(pkg-config --cflags python-3.5)
# or
# python3 setup.py install --record files.txt --user
@guyarad
guyarad / mongodb_collection_sizes.js
Last active Dec 29, 2019 — forked from joeyAghion/mongodb_collection_sizes.js
List mongodb collections in descending order of size. Helpful for finding largest collections. First number is "size," second is "storageSize."
View mongodb_collection_sizes.js
function getReadableFileSizeString(fileSizeInBytes, decimalPlacer=1) {
// for more concise solutions see: https://stackoverflow.com/questions/10420352/converting-file-size-in-bytes-to-human-readable-string
var i = 0;
var scale = 1024;
var byteUnits = [' B', ' KiB', ' MiB', ' GiB', ' TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
while (fileSizeInBytes >= scale) {
fileSizeInBytes = fileSizeInBytes / scale;
i++;
}
@guyarad
guyarad / pycharm-intellisense-issues.py
Last active Jul 30, 2019
PyCharm issuing wrong and annoying intellisense warnings (Python 2.7.14, PyCharm 2017.3.2)
View pycharm-intellisense-issues.py
# Python 2.7.14, PyCharm 2017.3.2
from collections import defaultdict
some_default_dict = defaultdict(list)
some_default_dict[1] = 'a'
some_default_dict[2] = 'b'
some_objects = [{'id': i} for i in range(10)]
obj_by_id = {obj['id']: obj for obj in some_objects}
@guyarad
guyarad / timing.py
Created Feb 8, 2017
Timing context manager
View timing.py
@contextmanager
def timing(label=None, time_func=simulator.timestamp):
"""
Can be used in conjunction with ``with`` statement to easily measure duration.
Args:
time_func:
label: represents the measurement
Returns:
A callable. Once invoked will return one of the following (duration in seconds):
View lazy_logging_benchmark.py
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("log")
def simple():
if logger.isEnabledFor(logging.DEBUG):
logger.debug('Stupid log message ' + ' '.join([str(i) for i in range(20)]))
@guyarad
guyarad / lazy_logging.py
Last active Nov 11, 2016
Lazy Logging - the below snippet is relevant when you wish to log some debugging information, but that information is relatively costly to generate. Ideally, you'll want to generate that information only when DEBUG level is actually enabled. In other words, only when the message formatting actually occurs.
View lazy_logging.py
# IMPLEMENTATION
class LazyLogging(object):
"""
A utility class that wraps a method
"""
def __init__(self, function):
self.function = function
def __str__(self):
You can’t perform that action at this time.