Skip to content

Instantly share code, notes, and snippets.

@klauern
klauern / winpath.sh
Created April 15, 2017 16:15
Change a Unix path in to Windows path for WSL
winpath() {
# get the Windows user path, convert to Unix line endings
user_path=$(echo "$(/mnt/c/Windows/System32/cmd.exe /C echo %HOMEDRIVE%%HOMEPATH%)" | tr -d "\r")
# expand the specified path
target_path=$(readlink -f $1)
# change ~ to $user_path
if grep -q "^/home/" <<< $target_path; then
temp_user_path=$(echo "$user_path" | sed -e 's|\\|/|g' -e 's|^\([A-Za-z]\)\:/\(.*\)|/mnt/\L\1\E/\2|' -e 's|^M$||')
@klauern
klauern / gist:154687
Created July 25, 2009 04:06 — forked from charlesroper/gist:65931
Method to detect whether we are running from an elevated command-prompt under Vista/Win7 or Administrator in WinXP
#
# Method to detect whether we are running from an elevated command-prompt
# under Vista/Win7 or as part of the local Administrators group in WinXP.
#
def elevated?
whoami = `whoami /groups` rescue nil
if whoami =~ /S-1-16-12288/
true
else
admin = `net localgroup administrators | find "%USERNAME%"` rescue ""
@klauern
klauern / example_gist_create.rb
Created March 20, 2009 14:48 — forked from schacon/example_gist_create.rb
Ruby Gist creator fork
require 'net/http'
require 'uri'
# /api/v1/:format/new
# /api/v1/:format/gists/:user
# /api/v1/:format/:gist_id
res = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'),
{ 'files[file1.ab]' => 'CONTNETS',
'files[file2.ab]' => 'contents' })
@klauern
klauern / gist:77201
Created March 10, 2009 23:19 — forked from tony-landis/gist:31445
Simple HTTP POST/GET helper in Groovy fork
/**
* A Simple HTTP POST/GET Helper Class for Groovy
*
* @author Tony Landis
* @copyright 2007 Tony Landis
* @website http://www.tonylandis.com
* @license BSD License (http://www.opensource.org/licenses/bsd-license.php)
* @example h = new GroovyHTTP('http://www.google.com/search')
* h.setMethod('GET')
* h.setParam('q', 'groovy')