Skip to content

Instantly share code, notes, and snippets.

View mollyporph's full-sized avatar

Otto Remse mollyporph

  • Forefront Consulting
  • Sweden
View GitHub Profile
public static bool HasInternet()
{
var connectionProfile = NetworkInformation.GetInternetConnectionProfile();
return (connectionProfile != null &&
connectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess);
}
$shell = New-Object -ComObject "Shell.Application"
$iisx = 'c:\Program Files (x86)\IIS Express\iisexpress.exe'
$path = (Resolve-path .) # eller hårdkoda path eller ta in som parameter
"" > "$path/input.txt"
$params = "/port:8080","/path:$path"
Write-Host $params
Start-Process -FilePath $iisx -ArgumentList $params -NoNewWindow -RedirectStandardOutput output.txt -RedirectStandardInput input.txt
$shell.minimizeall()
import requests
url = 'http://somedomain'
basic = ('basic-un','basic-pw')
payload = {'someVar' : 'someVal'}
customHeaders = {'content-type': 'application/json'}
result = requests.post(url,auth=basic,data=payload,headers=customHeaders)
@mollyporph
mollyporph / python webserver
Created August 25, 2015 14:04
Python webserver
import tornado.ioloop
import tornado.web
import tornado.httpclient
class MainHandler(tornado.web.RequestHandler):
def post(self):
data = self.request.body
print("Print from server: {0}".format(data))
self.write(data)
function hexToString(hexValue) {
var hex = hexValue.toString();
var str = '';
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
}
var dateVal = new Date(hexToString(aHexValueGoesHere));
#import PWM
#pwm = PWM(0x40)
#pwm.setPWMFreq(60) #60hz
servoMin = 1
servoMax = 800
def setPWMDegrees(channel,degrees):
clampedValue = max(1,min(degrees,360))
fraction = clampedValue / 360
@mollyporph
mollyporph / Update-DnsName.ps1
Last active March 31, 2017 05:22
A script to update dns-records at name.com
#---------STUFF THAT YOU SHOULD EDIT--
$username = "yourusername"
$apitoken = "yourapitoken" #Get an api-token at https://www.name.com/reseller usually doesn't take long
$domain = "yourdomain" #e.g example.com
$hostname = "yourhostname" #The hostname that you want to update, for mail.example.com the hostname should be "mail"
#
#------------------------------------
$headers = @{"Api-Username"= $username;"Api-Token" = $apitoken}
$listUrl = "https://api.name.com/api/dns/list/$domain"
@mollyporph
mollyporph / indexlinqlist.cs
Last active September 16, 2015 08:52
Indexed linq list
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
//Create a list of 20 anon objects wiht Name and Age
c:\windows\system32\powercfg.exe -change -monitor-timeout-ac 0
c:\windows\system32\powercfg.exe -change -monitor-timeout-dc 0
c:\windows\system32\powercfg.exe -change -disk-timeout-ac 0
c:\windows\system32\powercfg.exe -change -disk-timeout-dc 0
c:\windows\system32\powercfg.exe -change -standby-timeout-ac 0
c:\windows\system32\powercfg.exe -change -standby-timeout-dc 0
c:\windows\system32\powercfg.exe -change -hibernate-timeout-ac 0
c:\windows\system32\powercfg.exe -change -hibernate-timeout-dc 0
@mollyporph
mollyporph / rwp.fs
Created October 5, 2015 14:12
rwp bindings
type Res<'TSuccess,'TFailure> =
| Success of 'TSuccess
| Failure of 'TFailure
let succeed x =
Success x
let fail x =
Failure x
let either successFunc failureFunc x2Rop =
match x2Rop with
| Success s -> successFunc s