Skip to content

Instantly share code, notes, and snippets.

View golgor's full-sized avatar

Robert golgor

View GitHub Profile
@golgor
golgor / entrypoint.sh
Last active November 13, 2023 11:02
Keep a docker container running forever
# Can be used as 'docker run --name=name container --entrypoint /entrypoint.sh'
while :; # Run an endless loop,
do :; # of do nothing,
done & # as background task.
kill -STOP $! # Stop the background task.
wait $! # Wait forever, because background task process has been stopped.
# Alternative is using the tail command.
@golgor
golgor / and_or.py
Last active June 9, 2020 19:55
Using keyword "and" and "or". Not working the same way as in many other languages.
a = 0
b = 1
# If a is "falsy" a is returned, b/a is not evaluated (i.e. no division by zero error). Otherwise b/a is returned.
print(a and b/a)
s = ""
# Returning "" if the string is "". In any other case it returns the first character in the string.
# Avoiding trying to indexing s when s does not have any characters or of None type.
print(s and s[0])
@golgor
golgor / closures.py
Last active June 9, 2020 19:58
A way to create lambda functions in a loop without having problem with shared free variables.
# Returns a function with n preset when the function handle is created!
def adder(n):
def inner(x):
return x + n
return inner
# Creating preloaded functions
add_1 = adder(1)
add_100 = adder(100)