Skip to content

Instantly share code, notes, and snippets.

View ringe's full-sized avatar

Runar Ingebrigtsen ringe

View GitHub Profile
@ringe
ringe / README.md
Last active August 29, 2015 14:10
Prepare a Ubuntu 14.04 server for a rails app (with Norwegian support)
@ringe
ringe / bid_worker.rb
Created July 15, 2015 17:39
A Mechanize based Sidekiq Worker that reports on new public sector bid announcements in Norway
# A Mechanize based Sidekiq Worker that reports on new bid announcements in Norway
#
# This is used in a Rails app with a Bid model for storing known bids,
# and a BidMailer to send bid announcements to an email.
#
class BidWorker
include Sidekiq::Worker
sidekiq_options unique: true
def perform
def mama
csv = open("lookahere")
qtys=[]
fail=[]
csv.each_line do |l|
# Replace comma with period for float value
ln = l.gsub(/((?<=,"\d)(,)(?=\d",))/,".")
# Split line on comma
dt = ln.split(",")
b = Biditem.find_by_tu_no(dt[0])
@ringe
ringe / gist:2427980
Created April 20, 2012 11:48
/.well-known/browserid with Ruby
privkey = OpenSSL::PKey::RSA.new(2048)
pubkey = privkey.public_key
# Return BrowserID Identity JSON
def to_json
{
"public-key" => { "algorithm"=> "RS", "n" => public_key.n.to_s, "e" => public_key.e.to_s },
"authentication" => "/sign_in",
"provisioning" => "/provision"
}.to_json
@ringe
ringe / file1.js
Created April 20, 2012 12:46
BrowserID client certificate
{
"pubkey" :
{
"algorithm":"DS",
"y":"62b0ea6936a7ab30c95d8ffbbc77438a342faed99b6fc643a58f28d9ed2017177354f9f1d1d7e6b9e1c543780c3517953a124e66bc409fcaaa671d87a39cf897b32f47aaaffb7a3d297b89f9e116870a2182e2b2f84d68a7bc21a3f7934727e45e50a083e71a965d0cc320062598e407463f0c31cc2c20ed74d9bda98b21c902",
"p":"ff600483db6abfc5b45eab78594b3533d550d9f1bf2a992a7a8daa6dc34f8045ad4e6e0c429d334eeeaaefd7e23d4810be00e4cc1492cba325ba81ff2d5a5b305a8d17eb3bf4a06a349d392e00d329744a5179380344e82a18c47933438f891e22aeef812d69c8f75e326cb70ea000c3f776dfdbd604638c2ef717fc26d02e17",
"q":"e21e04f911d1ed7991008ecaab3bf775984309c3",
"g":"c52a4a0ff3b7e61fdf1867ce84138369a6154f4afa92966e3c827e25cfa6cf508b90e5de419e1337e07a2e9e2a3cd5dea704d175f8ebf6af397d69e110b96afb17c7a03259329e4829b0d03bbc7896b15b4ade53e130858cc34d96269aa89041f409136c7242a38895c9d5bccad4f389af1d7a4bd1398bd072dffa896233397a"
},
@ringe
ringe / file1.rb
Created April 20, 2012 12:58
Signing a BrowserID client certificate
# @private_key is an OpenSSL private key
# params is Rack request params, or Rails params
expiration = (Time.now.strftime("%s").to_i + params["duration"].to_i) * 1000
issue = { "iss" => "example.org",
"exp" => expiration,
"public-key" => params["pubkey"],
"principal" => { "email"=> "mormor@example.org" }
}
jwt = JSON::JWT.new(issue)
@ringe
ringe / gist:3112465
Created July 14, 2012 18:22
mama@rin.no login attempt to dev.myfavoritebeer.org
{
"log": {
"version": "1.2",
"creator": {
"name": "WebInspector",
"version": "536.11"
},
"pages": [],
"entries": [
{
@ringe
ringe / Gluster Volume
Created October 23, 2012 14:46
GlusterFS two-node replication with UCarp failover
$ sudo gluster volume info
Volume Name: data
Type: Replicate
Volume ID: 7ac35911-b9c2-4f20-a226-65a6173dafb3
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: gluster1:/data
@ringe
ringe / Export all Exchange mailboxes
Last active December 15, 2015 07:59
Say you want to export all your Exchange mailboxes to PST files, but would like to know which Active Directory "Windows" user names the mailboxes belongs to. Turns out it's not straightforward, unless there's something I don't get. First: Export a list of all AD users by their name, including their username - the one used in "DOMAIN\username", y…
# Then this in Exchange Management Shell
$Location = "\\server\pstexport"
New-Item -path $Location -name "migrate.txt" -type File -force
Add-Content "$Location\migrate.txt" "datasourceuser,destinationuser"
# Create a hash table of Exchange mailboxes
$mailboxes = @{}
Get-Mailbox | Select-Object name, alias |
ForEach-Object { $mailboxes.Add($_.name, $_.alias) }
@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 += $_