Skip to content

Instantly share code, notes, and snippets.

@davidberglund
davidberglund / privacypolicy
Last active November 10, 2016 13:59
privacy policy
karim enterprises Terms of Service and Privacy Policy
1. Terms
By using the Karim chatbot, you are agreeing to be bound by these terms of service, all applicable laws and regulations, and agree that you are responsible for compliance with any applicable local laws. If you do not agree with any of these terms, you are prohibited from using or accessing this site. The materials contained in this website are protected by applicable copyright and trademark law.
2. Use License
@davidberglund
davidberglund / check_installed_rpm.sh
Last active March 23, 2017 18:17
If command is not available: prompt install (Bash)
#!/bin/bash
which $1 >/dev/null 2>&1; if [ $? -eq 0 ]
then
echo "$1 is installed."
else
echo "$1 is not installed." >&2
echo
echo "Do you wish to install it?"
select yn in "Yes" "No"; do
@davidberglund
davidberglund / python_decorator_guide.md
Created March 29, 2019 17:09 — forked from Zearin/python_decorator_guide.md
The best explanation of Python decorators I’ve ever seen. (An archived answer from StackOverflow.)

NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.


Q: How can I make a chain of function decorators in Python?


If you are not into long explanations, see [Paolo Bergantino’s answer][2].

@davidberglund
davidberglund / Sample.vue
Created May 7, 2019 19:44 — forked from techlab23/Sample.vue
Vue Component
<template>
<div>
<h1> {{ message }} </h1>
<div
</template>
<script>
export default {
/* Child component registration */
components: {},
@davidberglund
davidberglund / gist:1f6d3221fe7a227a2316ce4ba73ee4f4
Last active July 30, 2019 08:21
accessing getters/setters from outside a Svelte component
// App.svelte
<script>
export let area = 51;
</script>
<main>
<p>{area}</p>
</main>
// main.js
import './main.pcss';
@davidberglund
davidberglund / delta.py
Created February 27, 2023 09:03
python time delta usage
import datetime
from datetime import timedelta
now = datetime.datetime.now()
delta = timedelta(
days=0,
seconds=1000000000,
microseconds=0,
milliseconds=0,
minutes=0,
hours=0,
@davidberglund
davidberglund / stopwatch.py
Created February 27, 2023 09:06
python stopwatch
import time
starttime = time.time()
lasttime = starttime
lapnum = 1
value = ""
print("Press ENTER for each lap.\nType Q and press ENTER to stop.")
while value.lower() != "q":
# Recursively search for any number of patterns in whole files with a specified file extension and with any number of patterns.
# Print matching files filenames and contents (squashed to one line)
cat <(for i in $(grep -rl PATTERN1 --include="*.*" /path/to/search); do echo $i && cat $i|xargs 2>/dev/null ; done)|awk '/PATTERN2/ && /PATTERN3/ {n = 2} n {print prev; n--} {prev = $0} END {if (n) print}'
# Look only for matches on a single line
for i in $(grep -rl PATTERN1 --include="*.*" /path/to/search); do echo $i && cat $i | awk '/PATTERN2/ && /PATTERN3/' ; done
for i in $(find "/some/path" -type f -name "*"); do echo $i && cat $i | awk '/PATTERN1/ && /PATTERN2/ && /PATTERN3/' ; done
# For long lists of files so we can step through
cat <(for i in $(grep -rl PATTERN1 --include="*.*" /path); do echo $i && cat $i | awk '/PATTERN1/ && /PATTERN2/ && /PATTERN3/' ; done)|less
cat <(for i in $(find "/some/path" -type f -name "*"); do echo $i && cat $i | awk '/PATTERN1/ && /PATTERN2/ && /PATTERN3/' ; done)|less