Skip to content

Instantly share code, notes, and snippets.

View ar45's full-sized avatar

Aron Podrigal ar45

  • AronTel
  • Chicago, IL
View GitHub Profile
@ar45
ar45 / chrome-cgroup.service
Created January 11, 2018 19:18
Limit Google Chrome Memory Hungry Eating up 32GB of ram
[Unit]
Description=Chrome browsers cgroup
After=multi-user.target
[Service]
ExecStart=/bin/bash -x -c '[ -d /sys/fs/cgroup/memory/user.slice/chrome ] || /bin/mkdir /sys/fs/cgroup/memory/user.slice/chrome; chmod 766 /sys/fs/cgroup/memory/user.slice/chrome/tasks; echo "Satrting"; CHROME_MEMORY_LIMIT_IN_BYTES=${CHROME_MEMORY_LIMIT_IN_BYTES:-5368709120}; echo "${CHROME_MEMORY_LIMIT_IN_BYTES}" >/sys/fs/cgroup/memory/user.slice/chrome/memory.limit_in_bytes; echo "Setting CHROME_MEMORY_LIMIT_IN_BYTES=${CHROME_MEMORY_LIMIT_IN_BYTES}";'
;ExecStart=/bin/mkdir /sys/fs/cgroup/memory/user.slice/chrome
;ExecStop=/bin/rm /sys/fs/cgroup/memory/user.slice/chrome
EnvironmentFile=-/etc/environment
Type=oneshot
@ar45
ar45 / addr.sh
Created February 19, 2017 19:52
Pure shell IPv4 subnet calculations
#!/bin/sh
exit_error()
{
echo "$1" >&2 && exit 1
}
valid_ip()
{
@ar45
ar45 / sqlalchemy_middleware.py
Created February 13, 2017 01:59
Quick dirty SQLAlchemy middleware for django < 1.9
from sqlalchemy.engine import create_engine
from sqlalchemy.orm import sessionmaker
def create_engine_from_django_settings(database='default'):
from django.conf import settings
db = settings.DATABASES[database]
engine = db['ENGINE'].lower()
if 'postgresql' in engine:
sqlalchemy_engine = 'postgresql'
for file in `cat files.txt`;
do
outfile=/tmp/`basename $file`;
ffmpeg -i $file -ar 8000 -ac 1 -acodec pcm_s16le -ab 128k $outfile \
&& mv $outfile $file;
done;
@ar45
ar45 / postgres_drop_tables.sql
Created September 14, 2016 21:19
Drop all tables in a schema - postgres
DO $$
DECLARE
stmt TEXT;
BEGIN
FOR stmt IN SELECT 'DROP TABLE IF EXISTS "' || tablename || '" CASCADE;'
from pg_tables
WHERE schemaname = 'public'
LOOP
EXECUTE stmt;
END LOOP;
@ar45
ar45 / lru_cache.py
Created September 1, 2016 02:05
python LRU cache instance method return value
from functools import lru_cache, wraps
class cached_method:
"""Decorotor for class methods.
Using pythons non data descriptor protocol, creates a new `functools.lru_cache` funcion wrapper
on first access of a instances method to cache the methods return value.
"""
def __new__(cls, func=None, **lru_kwargs):
if func is None:
@ar45
ar45 / jenkins.groovy
Created August 22, 2016 05:31
Jenkins extract commit from comment
def thr = Thread.currentThread()
def build = thr?.executable
def env = build.getBuildVariables()
//def env = build.getEnvironment()
println env
def ghprbCommentBody = env.get("ghprbCommentBody")
println "ghprbCommentBody=$ghprbCommentBody"
@ar45
ar45 / angularjs_directive_attribute_explanation.md
Created February 25, 2016 02:35 — forked from CMCDragonkai/angularjs_directive_attribute_explanation.md
JS: AngularJS Directive Attribute Binding Explanation

AngularJS Directive Attribute Binding Explanation

When using directives, you often need to pass parameters to the directive. This can be done in several ways. The first 3 can be used whether scope is true or false. This is still a WIP, so validate for yourself.

  1. Raw Attribute Strings

    <div my-directive="some string" another-param="another string"></div>
@ar45
ar45 / useful_bash_features.md
Created February 25, 2016 02:31 — forked from CMCDragonkai/useful_bash_features.md
Bash: Useful Bash Features

Useful Bash Features

  • Ctrl + r - search through command history
  • Alt + * - expand the * before running
  • Ctrl + Alt + e - expand the variables and aliases before running
  • Alt + # - turn current command into a comment and put it into history
function interpolateUrl(url, params, replaceMissing) {
return url.replace(/:([^\/]+)/g, (match, p1) => {
return params[p1] || ( replaceMissing ? '' : match );
});
}