Skip to content

Instantly share code, notes, and snippets.

View stigok's full-sized avatar
🚢
ship it!

Stig Otnes Kolstad stigok

🚢
ship it!
View GitHub Profile
@stigok
stigok / inotify-set-permissions.sh
Last active February 23, 2020 13:43
Automatically set permissions on uploaded files and folders to use in, for example, multi-user FTP environments where different clients set different permissions, or otherwise ignore umask.
#!/bin/bash
# stig@stigok.com Oct 2019
#
# Reference:
# http://positon.org/a-solution-to-the-umask-problem-inotify-to-force-permissions
set -x
# Take the directory name as argument
inotifywait -mrq -e CREATE --format %w%f "$1" | while read FILE
do
@stigok
stigok / mongobackup-s3.sh
Created December 13, 2019 13:03
MongoDB database backup to S3
#!/bin/bash
# Backs up a complete mongodb database instance running on localhost and
# uploads a gzipped dump to an S3 bucket (in this case Scaleway Object Storage)
#
# Configure s3cmd with `s3cmd --configure`
set -eu
MONGODB_USER=${MONGODB_USER}
MONGODB_PASSWORD=${MONGODB_PASSWORD}
@stigok
stigok / title.js
Created May 28, 2019 19:00
<body onfocus="I=21/7" onblur="I=4;look4luv(this)">
function look4luv (find, the, love, and, u, will, know) {
if (--I <3) return
the = find ? find.document : u || will || know || the || love
love = '<3'
find = (u || know || the || love)
u = undefined
u ?
will :
(find || the).title = the.title.endsWith(love) ? the.title.substr(0, the.title.length - love.length) : the.title +
@stigok
stigok / soundcloudplayer.js
Last active May 28, 2019 06:59
Angular.js SoundCloud player widget directive
angular.module('ngApp')
.directive('soundCloudPlayer', function () {
return {
restrict: 'E',
template: '<iframe width="100%" height="465" scrolling="no" frameborder="no"></iframe>',
link: function (scope, element, attrs) {
var iframe = element.find('iframe');
var settings = [
'buying=false',
'liking=false',
@stigok
stigok / setbrightness.sh
Last active November 17, 2018 16:38
Set Intel backlight brightness level Linux bash (Samsung NP300V3A-SE07)
#!/bin/bash
#
# Set brightness of intel backlight
# Usage:
# setbrightness
# Print current brightness
# setbrightness <level>
# Set brightness to <level> 1-10
# setbrightness less
# Set brightness to current level - 1
@stigok
stigok / install_opensuse.sh
Last active August 15, 2018 03:28
PrivateInternetAccess.com OpenVPN installation script for OpenSUSE 13.2
#! /bin/sh -
#
# Install OpenVPN connections for all available
# regions to NetworkManager
#
# Important:
# This is a modified version of the official Ubuntu script PrivateInternetAccess.com
# released at https://www.privateinternetaccess.com/installer/install_ubuntu.sh
# Automatic installation of python and openvpn has been removed, and needs to be
# installed manually before installation.
@stigok
stigok / tf_plan.txt
Last active May 3, 2018 14:24
Terraform debug output for github issue at https://github.com/sl1pm4t/terraform-provider-kubernetes
$ tf plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
kubernetes_namespace.default: Refreshing state... (ID: tkp-test)
kubernetes_stateful_set.ingestor: Refreshing state... (ID: tkp-test/pingers)
------------------------------------------------------------------------
import queue
import threading
import sys
class ThreadedQueue:
def __init__(self, task, timeout=10):
self.threads = dict()
self.queues = dict()
self.task = task
self.timeout = timeout
@stigok
stigok / file1.py
Last active February 6, 2018 21:25
Python 3: how to import methods from a different file in same folder
def test():
print("Test method")
if __name__ == "__main__":
print("Main method")
@stigok
stigok / setbrightness
Created January 30, 2018 15:08
Script to set brightness in steps. Never to 0.
# Set screen brightness
# Usage: setbrightness more|less|<int>
DIR="/sys/class/backlight/intel_backlight"
MAX_VALUE=$( < $DIR/max_brightness )
MAX_STEP=${MAX_STEP:-8}
STEP_AMOUNT=$(( $MAX_VALUE / $MAX_STEP ))
CURRENT_VALUE=$( < $DIR/brightness )
CURRENT_STEP=$(( $CURRENT_VALUE / $STEP_AMOUNT ))