Skip to content

Instantly share code, notes, and snippets.

View ringe's full-sized avatar

Runar Ingebrigtsen ringe

View GitHub Profile
@ringe
ringe / newapp.rb
Created February 7, 2012 09:41
Rails Template with Cucumber, RSpec, FactoryGirl, Capybara, Spork, Watchr, Devise on MySQL in a Vagrant environment
# Add to the given file the given lines, after the line with the given text, or replace the content
def add_to_file(path, text, after=nil, replace=false)
lines = []
if replace
lines = text
else
File.readlines(path).each do |line|
if after != nil and line.include?(after)
lines << line
lines << text
@ringe
ringe / README.md
Last active May 22, 2022 14:10
KVM QCOW2 Live backup

Live backup of KVM virtual machines

This script will let you make backups of live VMs running on KVM, using libvirt.

The backup job will suspend the VM for the time it takes to copy the RAM to disk.

Credits: Luca Lazzeroni

I've made some minor adjustments.

@ringe
ringe / gist:8779220c628ca326d2dcacae33562b01
Created August 6, 2021 16:12 — forked from pitch-gist/gist:2999707
HTML: Simple Maintenance Page
<!doctype html>
<title>Site Maintenance</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
</style>
@ringe
ringe / file1.rb
Created May 4, 2012 10:18
Find and extract every email address from IMAP folder
chars = %w{ | / - \\ }
def find_all_email_addresses_in(base_folder)
# Bash goodness :P
a=`find #{base_folder} -type d -name cur`.split("\n") +`find #{base_folder} -type d -name new`.split("\n")
@emails=[]
# http://stackoverflow.com/questions/535644/find-email-addresses-in-large-data-stream
a.each do |folder|
Dir[folder+"/*"].each do |email|
content = File.read(email)
r1 = Regexp.new(/(((From|^To|Cc):.*<)\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b(>))/)
@ringe
ringe / logcat
Created August 30, 2018 06:42
AudioBroadCast thread issue
01-02 23:03:04.941 13664-13664/com.royalone.audiobroadcast E/MultiWindowProxy: getServiceInstance failed!
01-02 23:03:05.134 13664-13664/com.royalone.audiobroadcast A/MainActivity: initAudioManager
01-02 23:03:05.163 13664-13664/com.royalone.audiobroadcast A/WiredHeadsetOn =: aatrue
01-02 23:03:05.164 13664-13664/com.royalone.audiobroadcast A/AudioBroadCast: MainActivity onCreate
01-02 23:03:05.164 13664-13664/com.royalone.audiobroadcast A/MainActivity: turnOnAudioService
01-02 23:03:05.363 13664-13664/com.royalone.audiobroadcast E/WifiManager: mWifiServiceMessenger == null
01-02 23:03:05.442 13664-13664/com.royalone.audiobroadcast A/UPnPAudioService: onCreate
01-02 23:03:05.446 13664-13664/com.royalone.audiobroadcast A/UPnPAudioService: onStartCommand
01-02 23:03:05.805 13664-13664/com.royalone.audiobroadcast A/AudioBroadCast: UpnpService Connected
01-02 23:03:05.811 13664-13664/com.royalone.audiobroadcast E/WifiManager: mWifiServiceMessenger == null
@ringe
ringe / limited_visma_global.ps1
Last active June 16, 2017 13:37
Limit the number of processes
# We only have a limited number of user licenses available for a given application
# So we execute the application through a script informing the user of the limit
# To reduce support requests, we tell the user who to talk to to release a license
# See also https://stackoverflow.com/q/1802127/1062276
# The executable we want to limit
$limited_app = "rg_cli.exe"
# Information about the limit
$app_name = "Visma Global"
@ringe
ringe / rdoc-field.vim
Last active November 20, 2016 00:03
Transform ActiveRecord db/schema.rb field lines to Rdoc list item with Vim
" use :RDF after copying lines from db/schema.rb to the class documentation
" the command transforms db/schema.rb lines to RDoc formatted list item
command -range=% RDF <line1>,<line2>s/\s\+t\.\(\w\+\)\s\+"\(.*\)"\($\|,.*\)/# +:\2+ _\1_::/
@ringe
ringe / maximum_users.ps1
Created July 28, 2016 10:00
Maximum users of an application, limit license usage on Windows Terminal Server
# name of procsess we are tracking
$limited_process = "notepad.exe"
# limit of instances we allow
$user_limit = 3
# Limit reached message and title
$message = "Too many users! They are:"
$title = "No more notepad"
@ringe
ringe / editablepage.html
Created January 9, 2014 11:07
Combine Trumbowyg with RestInPlace. I had some difficulties extending RestInPlaceEditor.forms with the "trumbowyg" type. Mainly because the callbacks are not documented in Trumbowyg, I believe. I was not able to use the RestInPlace method _this.update(); but had to copy the code from restinplace.js and implement a custom ajax handling. This leav…
<div id=page_1 data-url=/pages/1><>
<h1 class="rest-in-place" data-attribute="title">Nord-Norges stØrste næringsmagasin</h1>
<div id=pagebody_1 class="pagebody" data-attribute="body" data-formtype="trumbowyg" tabindex=1>
<h1>mama</h1>
<p>written text</p>
</div>
<script>
$("#pagebody_1").restInPlace();
</script>
@ringe
ringe / logoff_sessions.ps1
Created November 21, 2013 10:29
Logg off all Citrix user session in PowerShell
$timeout = 300
$message = "Please save your work. You will be logged off in "+ $timeout/60 +" minutes"
$sessions = @()
# Collect session IDs and warn users
query session | select-string "wdica" |
%{$_ -replace " {2,27}"," "} |
foreach {$_.ToString().split(" ")[3]} |
foreach {
$sessions += $_