mathz.nu Asterisk Blacklist Hobby webbhotell

2016/11/07

MAC adress mapping in Ubuntu

Filed under: Ubuntu — Mathz @ 00:08

/etc/udev/rules.d/70-persistent-net.rules

2016/11/01

Micropyhton esp8266 JSON client

Filed under: esp8266 — Mathz @ 13:55

# Sample code to request the state fron JSON service.


API_PASSWORD = 'YOUR_PASSWORD'
URL = 'http://x.x.x.x:xxxx/api/states/'
ENTITY = 'sensor'
TIMEOUT = 30
PIN = 5

def get_data():
import urequests
url = '{}{}'.format(URL, ENTITY)
headers = {'x-ha-access': API_PASSWORD,
'content-type': 'application/json'}
resp = urequests.get(URL, headers=headers)
return resp.json()['state']

def main():
import machine
import time

pin = machine.Pin(PIN, machine.Pin.OUT)
while True:
try:
if int(get_data()) >= 20:
pin.high()
else:
pin.low()
except TypeError:
pass
time.sleep(TIMEOUT)

if __name__ == '__main__':
print('Get the state of {}'.format(ENTITY))
main()

2016/10/30

Start network on esp8266

Filed under: esp8266 — Mathz @ 08:46

Configure network as client
import network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect('ssid', 'password')

Show IP-adress
wlan.ifconfig()

Configure network as access Point

import network
ap = network.WLAN(network.AP_IF)
ap.active(True)
ap.config(essid="network-name", authmode=network.AUTH_WPA_WPA2_PSK, password="abcdabcdabcd")

2016/09/05

Backup of MSSQL database

Filed under: Server — Mathz @ 09:56

Create stored procedure.


// Copyright © Microsoft Corporation. All Rights Reserved.
// This code released under the terms of the
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)
USE [master]
GO
/****** Object: StoredProcedure [dbo].[sp_BackupDatabases] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

— =============================================
— Author: Microsoft
— Create date: 2010-02-06
— Description: Backup Databases for SQLExpress
— Parameter1: databaseName
— Parameter2: backupType F=full, D=differential, L=log
— Parameter3: backup file location
— =============================================

CREATE PROCEDURE [dbo].[sp_BackupDatabases]
@databaseName sysname = null,
@backupType CHAR(1),
@backupLocation nvarchar(200)
AS

SET NOCOUNT ON;

DECLARE @DBs TABLE
(
ID int IDENTITY PRIMARY KEY,
DBNAME nvarchar(500)
)

— Pick out only databases which are online in case ALL databases are chosen to be backed up
— If specific database is chosen to be backed up only pick that out from @DBs
INSERT INTO @DBs (DBNAME)
SELECT Name FROM master.sys.databases
where state=0
AND name=@DatabaseName
OR @DatabaseName IS NULL
ORDER BY Name

— Filter out databases which do not need to backed up
IF @backupType=’F’
BEGIN
DELETE @DBs where DBNAME IN (‘tempdb’,’Northwind’,’pubs’,’AdventureWorks’)
END
ELSE IF @backupType=’D’
BEGIN
DELETE @DBs where DBNAME IN (‘tempdb’,’Northwind’,’pubs’,’master’,’AdventureWorks’)
END
ELSE IF @backupType=’L’
BEGIN
DELETE @DBs where DBNAME IN (‘tempdb’,’Northwind’,’pubs’,’master’,’AdventureWorks’)
END
ELSE
BEGIN
RETURN
END

— Declare variables
DECLARE @BackupName varchar(100)
DECLARE @BackupFile varchar(100)
DECLARE @DBNAME varchar(300)
DECLARE @sqlCommand NVARCHAR(1000)
DECLARE @dateTime NVARCHAR(20)
DECLARE @Loop int

— Loop through the databases one by one
SELECT @Loop = min(ID) FROM @DBs

WHILE @Loop IS NOT NULL
BEGIN

— Database Names have to be in [dbname] format since some have – or _ in their name
SET @DBNAME = ‘[‘+(SELECT DBNAME FROM @DBs WHERE ID = @Loop)+’]’

— Set the current date and time n yyyyhhmmss format
SET @dateTime = REPLACE(CONVERT(VARCHAR, GETDATE(),101),’/’,”) + ‘_’ + REPLACE(CONVERT(VARCHAR, GETDATE(),108),’:’,”)

— Create backup filename in path\filename.extension format for full,diff and log backups
IF @backupType = ‘F’
SET @BackupFile = @backupLocation+REPLACE(REPLACE(@DBNAME, ‘[‘,”),’]’,”)+ ‘_FULL_’+ @dateTime+ ‘.BAK’
ELSE IF @backupType = ‘D’
SET @BackupFile = @backupLocation+REPLACE(REPLACE(@DBNAME, ‘[‘,”),’]’,”)+ ‘_DIFF_’+ @dateTime+ ‘.BAK’
ELSE IF @backupType = ‘L’
SET @BackupFile = @backupLocation+REPLACE(REPLACE(@DBNAME, ‘[‘,”),’]’,”)+ ‘_LOG_’+ @dateTime+ ‘.TRN’

— Provide the backup a name for storing in the media
IF @backupType = ‘F’
SET @BackupName = REPLACE(REPLACE(@DBNAME,'[‘,”),’]’,”) +’ full backup for ‘+ @dateTime
IF @backupType = ‘D’
SET @BackupName = REPLACE(REPLACE(@DBNAME,'[‘,”),’]’,”) +’ differential backup for ‘+ @dateTime
IF @backupType = ‘L’
SET @BackupName = REPLACE(REPLACE(@DBNAME,'[‘,”),’]’,”) +’ log backup for ‘+ @dateTime

— Generate the dynamic SQL command to be executed

IF @backupType = ‘F’
BEGIN
SET @sqlCommand = ‘BACKUP DATABASE ‘ +@DBNAME+ ‘ TO DISK = ”’+@BackupFile+ ”’ WITH INIT, NAME= ”’ +@BackupName+”’, NOSKIP, NOFORMAT’
END
IF @backupType = ‘D’
BEGIN
SET @sqlCommand = ‘BACKUP DATABASE ‘ +@DBNAME+ ‘ TO DISK = ”’+@BackupFile+ ”’ WITH DIFFERENTIAL, INIT, NAME= ”’ +@BackupName+”’, NOSKIP, NOFORMAT’
END
IF @backupType = ‘L’
BEGIN
SET @sqlCommand = ‘BACKUP LOG ‘ +@DBNAME+ ‘ TO DISK = ”’+@BackupFile+ ”’ WITH INIT, NAME= ”’ +@BackupName+”’, NOSKIP, NOFORMAT’
END

— Execute the generated SQL command
EXEC(@sqlCommand)

— Goto the next database
SELECT @Loop = min(ID) FROM @DBs where ID>@Loop

END

 

Backup-MSQSQL.bat

sqlcmd -S .\SQLEXPRESS –E -Q “EXEC sp_BackupDatabases @backupLocation=’D:\SQLBackups\’, @backupType=’F'”

 

Took from: https://support.microsoft.com/en-us/kb/2019698

2016/07/28

Install Tomcat 8 on Ubuntu 16.04

Filed under: Server — Mathz @ 22:56

https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-ubuntu-16-04

2016/07/11

Tomcat 8 install Ubuntu 14.04

Filed under: Server — Mathz @ 20:38

https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-ubuntu-14-04

2016/06/16

Remove C# registration

Filed under: Programering — Mathz @ 20:52


Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\VCSExpress\9.0\Registration]
“Params”=-

2016/06/09

Oneliner to backup git repos from Gitolite

Filed under: GIT — Mathz @ 16:12

ssh <user>@<githost> info | sed -n ‘/^ R W/p’ | sed -r ‘s/^.{5}//’ | while read line ; do git clone ssh://<user>@<host>/$line ; done

2016/05/25

Telldus core install on Ubuntu

Filed under: Server — Mathz @ 21:47

Console based installation

Add the following lines to your /etc/apt/sources.list:

deb http://download.telldus.com/debian/ stable main

The Telldus public key for apt-secure can be downloaded  here. You can add this key with

sudo apt-key add telldus-public.key

or combine downloading and registering:

wget -q http://download.telldus.se/debian/telldus-public.key -O- | sudo apt-key add -

The key fingerprint is

70C4 10C9 D73D 53E8 38B3 1C58 5A94 9181 E501 EA76
Telldus Technologies AB <info.tech@telldus.se>

Update the repository

sudo apt-get update

To install telldus-core, do

sudo apt-get install telldus-core

Telldus SDK install Ubuntu from sources

Filed under: Server — Mathz @ 21:40

SDK Download here:
http://download.telldus.se/TellStick/Software/telldus-core/

sudo apt-get install doxygen build-essential libftdi1 libftdi-dev libconfuse0 libconfuse-dev cmake

wget http://developer.telldus.com/export/4342bbaa1dcd90011b66e8c1540db6ba904877fe/telldus-core/Doxyfile.in

« Newer PostsOlder Posts »

Powered by WordPress