amonkeysden-blog
amonkeysden-blog
a Monkey's Den
58 posts
Littering the internet with half formed ideas and projects never to be completed
Don't wanna be here? Send us removal request.
amonkeysden-blog · 8 years ago
Text
Hack to send a VLAN through a different gateway on Tomato dd-wrt
WAN_GWAY="0.0.0.0" while [ $WAN_GWAY == "0.0.0.0" ]; do sleep 3 WAN_GWAY=nvram get wan_gateway done ip route add default via $WAN_GWAY table 10 NO_VPN_LST="192.168.1.100 192.168.1.101 192.168.1.102 192.168.1.103 192.168.1.104 192.168.1.105 192.168.1.106 192.168.1.107 192.168.1.108 192.168.1.109 192.168.1.110 192.168.1.111 192.168.1.112 192.168.1.113 192.168.1.114 192.168.1.115 192.168.1.116 192.168.1.117 192.168.1.118 192.168.1.119 192.168.1.120 192.168.1.121 192.168.1.122 192.168.1.123 192.168.1.124 192.168.1.125 192.168.1.126 192.168.1.127 192.168.1.128 192.168.1.129 192.168.1.130 192.168.1.131 192.168.1.132 192.168.1.133 192.168.1.134 192.168.1.135 192.168.1.136 192.168.1.137 192.168.1.138 192.168.1.139 192.168.1.140 192.168.1.141 192.168.1.142 192.168.1.143 192.168.1.144 192.168.1.145 192.168.1.146 192.168.1.147 192.168.1.148 192.168.1.149" for ipa in $NO_VPN_LST; do ip rule add from $ipa table 10 done NO_VPN_LST="192.168.1.150 192.168.1.151 192.168.1.152 192.168.1.153 192.168.1.154 192.168.1.155 192.168.1.156 192.168.1.157 192.168.1.158 192.168.1.159 192.168.1.160 192.168.1.161 192.168.1.162 192.168.1.163 192.168.1.164 192.168.1.165 192.168.1.166 192.168.1.167 192.168.1.168 192.168.1.169 192.168.1.170 192.168.1.171 192.168.1.172 192.168.1.173 192.168.1.174 192.168.1.175 192.168.1.176 192.168.1.177 192.168.1.178 192.168.1.179 192.168.1.180 192.168.1.181 192.168.1.182 192.168.1.183 192.168.1.184 192.168.1.185 192.168.1.186 192.168.1.187 192.168.1.188 192.168.1.189 192.168.1.190 192.168.1.191 192.168.1.192 192.168.1.193 192.168.1.194 192.168.1.195 192.168.1.196 192.168.1.197 192.168.1.198 192.168.1.199" for ipa in $NO_VPN_LST; do ip rule add from $ipa table 10 done NO_VPN_LST="192.168.1.200 192.168.1.201 192.168.1.202 192.168.1.203 192.168.1.204 192.168.1.205 192.168.1.206 192.168.1.207 192.168.1.208 192.168.1.209 192.168.1.210 192.168.1.211 192.168.1.212 192.168.1.213 192.168.1.214 192.168.1.215 192.168.1.216 192.168.1.217 192.168.1.218 192.168.1.219 192.168.1.220 192.168.1.221 192.168.1.222 192.168.1.223 192.168.1.224 192.168.1.225 192.168.1.226 192.168.1.227 192.168.1.228 192.168.1.229 192.168.1.230 192.168.1.231 192.168.1.232 192.168.1.233 192.168.1.234 192.168.1.235 192.168.1.236 192.168.1.237 192.168.1.238 192.168.1.239 192.168.1.240 192.168.1.241 192.168.1.242 192.168.1.243 192.168.1.244 192.168.1.245 192.168.1.246 192.168.1.247 192.168.1.248 192.168.1.249" for ipa in $NO_VPN_LST; do ip rule add from $ipa table 10 done ip route flush cache
0 notes
amonkeysden-blog · 9 years ago
Link
Had to set up a GO Packages folder as well.
mkdir /usr/local/go/packages #maybe not best practice but it looks to have worked! sudo chown pi /usr/local/go/packages #this doesn't give any feedback so seems to take a while... go get github.com/gin-gonic/gin go get github.com/chbmuc/cec go get github.com/jessevdk/go-flags #now build the tool go build cec-web.go
and it failed....
pi@FamilyRoomPi:~/projects/cec-web$ go build cec-web.go # command-line-arguments ./cec-web.go:43: undefined: cec.List ./cec-web.go:49: undefined: cec.PowerOn ./cec-web.go:56: undefined: cec.Standby ./cec-web.go:63: undefined: cec.GetDevicePowerStatus ./cec-web.go:78: undefined: cec.Transmit ./cec-web.go:84: undefined: cec.VolumeUp ./cec-web.go:89: undefined: cec.VolumeDown ./cec-web.go:94: undefined: cec.Mute ./cec-web.go:102: undefined: cec.Key
looked at the cec package here: https://github.com/chbmuc/cec, created a test script that built and worked... hmmm...
0 notes
amonkeysden-blog · 9 years ago
Link
0 notes
amonkeysden-blog · 9 years ago
Link
0 notes
amonkeysden-blog · 9 years ago
Link
useful commands to increase the partition size...
0 notes
amonkeysden-blog · 11 years ago
Text
Sending rsnapshot reports to InfluxDB
https://github.com/thompsonson/scripts/blob/master/rsnapshot-influxdb.pl
Some simple config info https://github.com/thompsonson/scripts/blob/master/README.md
0 notes
amonkeysden-blog · 11 years ago
Text
Knockout.js links
KO Components
http://www.knockmeout.net/2014/06/knockout-3-2-preview-components.html
http://knockoutjs.com/documentation/component-overview.html
http://knockoutjs.com/documentation/component-binding.html
http://knockoutjs.com/documentation/component-custom-elements.html
KO data processing
https://github.com/raheelshan/knockout-search
KO Templates and HTML tags
https://github.com/mbest/knockout.punches
SPA
http://learn.knockoutjs.com/#/?tutorial=webmail
Paging
http://tech.pro/tutorial/1235/handling-paged-datasets-in-knockoutjs
0 notes
amonkeysden-blog · 11 years ago
Text
Free disk details to MQTT
Below if a Python script to publish the details from df on MQTT. I have a NodeRed installation subscribing, currently it publishes the data to an InfluxDB. Next step is to alert when use_pc (used percentage) hits 80%.
import paho.mqtt.client as mosquitto import os, json, socket # config topic = "/data/sysmon/" + socket.gethostname() + "/os/df" hostname = "localhost" port = 1883 client_id = "df_python_script" # connect to broker mosquittoClient = mosquitto.Mosquitto(client_id) mosquittoClient.connect(hostname, port) # process the data data = [s.split() for s in os.popen("df -P").read().splitlines()] #remove the header del data[0] for item in data:         dict = {'Filesystem':item[0], 'Size':item[1], 'Used':item[2], 'Avail':item[3], 'Use_pc':item[4].replace("%",""), 'Mounted':item[5]}         # publish it on the broker         mosquittoClient.publish(topic,json.dumps(dict)) mosquittoClient.disconnect()
0 notes
amonkeysden-blog · 11 years ago
Text
Installing Mosquitto MQTT broker on Raspberry Pi
First add the Mosquitto repo (the standard one doesn't have the latest version that works with the Python interface), instructions here:
http://mosquitto.org/2013/01/mosquitto-debian-repository/
Mosquitto is installed from the Mosquitto package repo:
sudo apt-get install mosquitto sudo apt-get install mosquitto-clients
The python interface is available from pip
sudo pip install paho-mqtt
To test it subscribe on one command prompt and publish on another
Subscribe
mosquitto_sub -d -t hello/world
In another window Publish
mosquitto_pub -d -t hello/world -m "Message To Send"
0 notes
amonkeysden-blog · 11 years ago
Text
create script from history
# create script from history foreach ($i in Get-History){Add-Content c:\script.ps1 $i.CommandLine}
0 notes
amonkeysden-blog · 12 years ago
Text
Update the app.config form within application code
private static void UpdateSetting(string key, string value) { Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); configuration.AppSettings.Settings[key].Value = value; configuration.Save(); ConfigurationManager.RefreshSection("appSettings"); } private static void UpdateConnectionString(string key, string value) { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); var connectionStrings = xmlDocument.SelectNodes("configuration/connectionStrings/add"); foreach (XmlNode node in connectionStrings) { if (node.Attributes["name"].Value == key) { node.Attributes["connectionString"].Value = new System.Configuration.ConnectionStringSettings(key, value).ToString(); } } xmlDocument.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); ConfigurationManager.RefreshSection("connectionStrings"); }
0 notes
amonkeysden-blog · 12 years ago
Text
a note to help remember - grep in PowerShell
(gc $ENV:windir\WINDOWSUPDATE.LOG)|Select-string -AllMatches "FATAL"
is a lot slower than
Select-string -Path $ENV:windir\WINDOWSUPDATE.LOG  -AllMatches "FATAL"
Have you looked at the times with Measure-Command? With my laptop it came in at 5600 and 247 milliseconds, respectively. Just to get the output I'd say the later is better.
1 note · View note
amonkeysden-blog · 12 years ago
Text
SQLite Database First Model generation for web2py
Found a great tool to model datbases, the project is here. Interestingly they can be exported to different formats including web2py.
The below script creates the XML for the web tool from a SQLite DB. It uses the sqlite.exe's -csv parameter and Powershell's ConvertFrom-CSV function to easily use the returned data. 
[xml] $XMLdocument = @" <?xml version="1.0" encoding="utf-8" ?> <sql> <datatypes db="web2py"> <group label="Numeric" color="rgb(238,238,170)"> <type label="Integer" length="1" sql="integer" re="INTEGER" quote=""/> <type label="Double precision" length="1" sql="double" re="DOUBLE" quote=""/> </group> <group label="Character" color="rgb(255,200,200)"> <type label="String" length="1" sql="string" quote="'"/> <type label="Text" length="1" sql="text" quote="'"/> <type label="BLOB" length="1" sql="blob" quote="'"/> </group> <group label="Date & Time" color="rgb(200,255,200)"> <type label="Time" length="0" sql="time" quote="'"/> <type label="Date" length="0" sql="date" quote="'"/> <type label="Datetime" length="0" sql="datetime" quote="'"/> </group> <group label="Miscellaneous" color="rgb(200,200,255)"> <type label="Boolean" length="0" sql="boolean" quote=""/> <type label="Upload" length="0" sql="upload" quote=""/> <type label="Password" length="0" sql="password" quote=""/> </group> </datatypes> </sql> "@ sqlite3.exe -csv test.mmb "select tbl_name from sqlite_master where type = 'table';" | ConvertFrom-Csv -Header tbl_name | % { #"$($_.tbl_name)"; # create a table node $table_node = $XMLdocument.CreateElement("table") $name = $XMLdocument.CreateAttribute("name") $name.Value = $($_.tbl_name) $table_node.Attributes.Append($name) sqlite3.exe -csv test.mmb "PRAGMA table_info($($_.tbl_name))" | ConvertFrom-Csv -header cid,name,type,notnull,dflt_value,pk | %{ #"`t $($_.name) " # create and append a row node $row_node = $XMLdocument.CreateElement("row") $name = $XMLdocument.CreateAttribute("name") $name.Value = $($_.name) $row_node.Attributes.Append($name) #notnull $null_node = $XMLdocument.CreateAttribute("null") $null_node.Value = $([int] -not ($([int] $_.pk) -or $([int] $_.notnull))) $row_node.Attributes.Append($null_node) $datatype_node = $XMLdocument.CreateElement("datatype") $datatype_node.InnerText = $($_.type) $row_node.AppendChild($datatype_node) $default_node = $XMLdocument.CreateElement("default") if ($($_.dflt_value) -eq "") { $default_value = "NULL" } else { $default_value = ($_.dflt_value) } $default_node.InnerText = $default_value $row_node.AppendChild($default_node) $table_node.AppendChild($row_node) if ($_.pk -eq 1) { # set the primary key value $key_node = $XMLdocument.CreateElement("key") $name = $XMLdocument.CreateAttribute("type") $name.Value = "PRIMARY" $key_node.Attributes.Append($name) $part_node = $XMLdocument.CreateElement("part") $part_node.InnerText = $($_.name) $key_node.AppendChild($part_node) $table_node.AppendChild($key_node) } } $XMLdocument.sql.AppendChild($table_node) } $XMLdocument.Save("d:\model.xml") #ii d:\model.xml'
1 note · View note
amonkeysden-blog · 14 years ago
Link
51 notes · View notes
amonkeysden-blog · 14 years ago
Text
Debugging and Killing an Amazon S3 Backup Job on the QNAP
http://forum.qnap.com/viewtopic.php?f=15&t=27324&p=186889
46 notes · View notes
amonkeysden-blog · 14 years ago
Text
More profile stuff
more meaningful and different colours plus some transcript logging
# log everything $logfile = "$(Get-Date -uformat "%Y%m%d - %H%M%S").log" Start-Transcript -Path $logfile # this is hear to make it more readable (Get-Host).PrivateData.WarningBackgroundColor = "Black" (Get-Host).PrivateData.WarningForegroundColor = "Green" (Get-Host).PrivateData.ErrorForegroundColor = "white" (Get-Host).PrivateData.ErrorBackgroundColor = "red" ..... Stop-Transcript
5 notes · View notes
amonkeysden-blog · 14 years ago
Text
amonkeyseulersolutions:
function factorial { [cmdletbinding()] param([int64] $x) if ($x -lt 1) { return "Has to be on a positive integer" } if ($x -eq 1) { [int64] $x } else { [int64] $x * (factorial ($x-1)) } }
I'm trying the challenges from Project Euler and on #3. I've been using factorials to find out if a number is prime.
My factorial function doesn't work to well for large factorials though. When the number of digits goes over 29 (very quick with factorials!) it becomes a double. I'm not sure what quite happens then but it's not what I expected! This is an example:
PS C:\Users\Matt> $f = factorial 29 PS C:\Users\Matt> $f 8.8417619937397E+30 PS C:\Users\Matt> ( $f) - ( $f+1) 0
that shouldn't equal zero... by my reckoning that should be -1...
A Google returned a few libraries (one on CodeProject written in C++) and notes on .Net 4 having a BigInt type (http://msdn.microsoft.com/en-us/library/system.numerics.biginteger%28VS.100%29.aspx). I don't want to mess around forcing my PowerShell to use v4 and the C++ is going into areas I'll get bored in!
Luckily more searching found this - http://fatbeards.blogspot.com/2009/10/using-f-bigint-in-powershell.html. It seems FatBeard has tried Project euler with PowerShell as well. :)
Here's the download: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=effc5bc4-c3df-4172-ad1c-bc62935861c5&displaylang=en
and here's the #fail!
# PS C:\Users\Matt> [Microsoft.FSharp.Math.BigInt] Unable to find type [Microsoft.FSharp.Math.BigInt]: make sure that the assembly containing this type is loaded. #
I suspect it worked for FatBeard as a previous version of FSharp worked with .net 2. It's now .Net v4 and changing the registry is still unappealing to me...
http://www.dougfinke.com/blog/index.php/2010/04/18/how-to-add-an-f-type-to-a-powershell-session/
but the powershell.exe.config looks like a better way, not least as i can get permissions to do that!
http://tfl09.blogspot.com/2010/08/using-newer-versions-of-net-with.html.
After some messing around here's the final function:
# Add-Type -Path "C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Numerics.dll" function factorial { [cmdletbinding()] param($x) if ($x -lt 1) { return "Has to be on a positive integer" } if ($x -eq 1) { $x } else { $y = factorial ($x-1) [System.Numerics.BigInteger]::Multiply($x , $y) } }
And to compare the issue above
# PS C:\Users\Matt> $f = factorial 29 PS C:\Users\Matt> $f - ($f + 1) IsPowerOfTwo : False IsZero : False IsOne : False IsEven : False Sign : -1 PS C:\Users\Matt> ($f - ($f + 1)).ToString() -1
Next up are the Prime factors of 600851475143
Calculating a factorial with PowerShell
28 notes · View notes