Installing Gitea (my own GitHub)

To install Gitea on a Synology under Docker you can pretty much follow the instructions found here

I used the custome setup with some minor changes to the USER-UID & USER-GID for the account I want to run under on the Synology. 

docker-compose.yml:

version: "2"
networks:
  gitea:
    external: false
services:
  server:
    image: gitea/gitea:latest
    environment:
      - USER_UID={enter User ID here}
      - USER_GID={enter Group ID here}
    restart: always
    networks:
      - gitea
    volumes:
      - ./gitea:/data
    ports:
      - "3000:3000"
      - "222:22"

The above will use a SQLite database which should be fine. 

When running “sudo docker-compose up -d” an error was generated for failing to mount “gitea” due to permissions. Manually creating the folder and re-running the command fixed the issue.

Checking Docker on the Synology finds that the container is running and connecting with a browser to http://{server}:3000 with bring up the Gitea page – woohoo!

 

Posted in Code, Docker | Tagged , , , | Leave a comment

SVN Quick Reference

View Repository
    svn ls svn://{server}/projects

Import New Folders in to Repository
   svn import {folder} svn://{server}/projects/{folder} -m "{comment}"

Checkout Folder/Files from Repository
  svn co svn://{server}/projects/{folder}

View Status of Files in Folder
  svn status

Checkin Changed Files to Repository
  svn commit -m "{comment}"

Pull Latest Files from Repository
  svn update

Posted in Code | Tagged , | Leave a comment

Docker Quick Reference

View/Change Container Status
    docker ps                 {list running containers}
    docker ps -a              {list all containers even exited ones}
    docker container pause ID {pause running container}
    docker container stop ID  {stop running container}
    docker container kill ID  {Kill a running container}
    docker logs -f ID         {continually follow output of container}
 
Access Running Container
   docker ps                               {find ID of running container}
   docker commit ID mysnapshot             {create a snapshot}
   docker run -t -i mysnapshot /bin/bash   {run a bash shell}
                                           {-i interactive, -t terminal}
 
Building/Running a Container {containing python code}
   docker build -t {name} .
   docker  run -i -t {name} python run.py
 
Deleting Images
   docker image list      {list images}
   docker rmi image_ID.   {remove image}
 
   If you are unable to delete due to container in use
      docker ps                   {get container name}
      docker rm container_name    {remove exited container}
      docker rmi image_id         {remove image}
 
Mounting Local File Systems
This will mount the current directory as /mnt/app for the container to access:
    docker run -it -v ${PWD}:/mnt/app instabot /bin/bash
 
Docker Documentation
 
 
Posted in Code, Docker | Leave a comment

Excel: Expand multi-line rows

How to end up with one row per entry in a spreadsheet when some cells contain multiple entries. This example will expand the data below in to multiple rows using a VB. Noting here for my reference.

The following code with take the above (Sheet1) content and create a new worksheet (Sheet2) with the expanded records. As the code expands both column D & E an error is thrown for row 4 as the same number of entries do not match in both cells.

Public Sub expandData()
    MsgBox "Make sure to have an Empty Sheet2"
    If Not IsEmpty(Worksheets("Sheet2").Range("A1").Value) Then
        MsgBox "Sheet2 looks like it has data?"
    Else
        Dim i As Long
        Dim insertrow As Long
        
        i = 1
        insertrow = 1
        Do While Not IsEmpty(Worksheets("Sheet1").Range("A" + CStr(i)).Value)
            insertrow = expandRow2("A" + CStr(i) + ":C" + CStr(i), "D" + CStr(i), "E" + CStr(i), insertrow)
            i = i + 1
        Loop
    End If
End Sub


Private Function expandRow2(copyrange As String, expcell As String, expcell2 As String, insertpoint As Long)
    Dim count As Integer
    Dim sa() As String
    Dim sb() As String
    Dim i As Integer
    
    count = Worksheets("Sheet1").Range(copyrange).Columns.count
    sa() = Split(Worksheets("Sheet1").Range(expcell).Value, vbLf)
    sb() = Split(Worksheets("Sheet1").Range(expcell2).Value, vbLf)
    
    If UBound(sa) <> UBound(sb) Then
        Worksheets("Sheet1").Range(copyrange).Copy Destination:=Worksheets("Sheet2").Range("A" + CStr(insertpoint))
        Worksheets("Sheet2").Cells(insertpoint, count + 1).Value = "#ERROR"
        insertpoint = insertpoint + 1
    Else
        For i = 0 To UBound(sa)
            Worksheets("Sheet1").Range(copyrange).Copy Destination:=Worksheets("Sheet2").Range("A" + CStr(insertpoint))
            Worksheets("Sheet2").Cells(insertpoint, count + 1).Value = sa(i)
            Worksheets("Sheet2").Cells(insertpoint, count + 2).Value = sb(i)
            insertpoint = insertpoint + 1
        Next i
    End If
    expandRow2 = insertpoint
End Function
Posted in Code, Microsoft, Software | Leave a comment

Creating an Alexa Skill to work with your Synology

I found this excellent article on creating a basic Alexa skill. Follow this tutorial to get a basic skill and use the php code below instead of the shell script in the tutorial as the Synology does not like non-PHP scripts.

<?php
 header("Content-Type: application/json;charset=utf-8");
?>
{ "version": "1.0", "response": { "outputSpeech": { "type": "PlainText", "text": "Got it. Yes, your command was received."} }}

In the Amazon skill testing you can see the JSON data sent to the Synology. After the tutorial you will find that that you are only sending the date and no other command data. To send more data the Amazon skill will need to be further developed.

More to come on linking the broadlink and Alexa skill

Posted in Code, Home Automation | Leave a comment

Broadlink RM IR control via Python

Christmas I received the Broadlink RM device for controlling IR devices with the intention of using it with Amazon Alexa. It turns out that the service is not available in the UK so the only way to control the device is with the phone App.

After ‘googling’ for options it turns out there are ways to bridge the connection using Android devices, which I don’t have. My next option was to look for ways to control the device through Python and create my own skills in Alexa.

Everything is easier said than done but here goes.

Step 1. make sure your broadlink RM device is on your network and you can see it with the phone App. Just follow the instructions in the box for this bit.

Step 2. I found a library on github to provide some basic API features. Download the API from user mjg59 on github. From this point you can follow the instructions on the README 🙂

or mine below…..

Step 3. I found that my install of Python did not have pyaes installed that is used by the API so ….. sudo pip install pyaes

Step 4. Okay, when I download the code from github I placed the contents of broadlink/__init__.py in to broadlink.py. You will need to do the same if you use the code below to learn one command from your remote and repeat it back out. This will prove you can communicate with the broadlink device and play out a recorded IR code.

import broadlink
import time

devices = broadlink.discover(timeout=5)
print(devices)

devices[0].auth()

devices[0].enter_learning()
print("learning")
time.sleep(5)
ir = devices[0].check_data()

print("wait")
time.sleep(10)

print("learnt")
devices[0].send_data(ir)
print(ir)
print("end")

Running the above will give you 5 seconds to learn an IR code (your broadlink should show an amber light) and 10 seconds later the broadlink will reply the command.

This proves you have control of your broadlink. The next stages will be to learn all your IR commands to build a database that Alexa can use.

Posted in Code, Home Automation | Leave a comment

Synology Certificates and Alexa Skills

If you want to host Alexa skills on your Synology you will need to use Let’s Encrypt certificates as the default one will not authenticate for the skill.

To check if your certificate is okay use SSLChecker to validate the certificate from the Synology. You should get all green ticks. Anything else will cause a failure while testing the skill.

Posted in Code, Home Automation | Leave a comment

Installing Screen on Synology

Home page for screen

To install on synology you need to have ipkg installed. Mine is located in /opt/bin.

sudo /opt/bin/ipkg install screen

If you just run /opt/bin/screen you will get a terminal error as you may not have a termcap entry. For me the fix was:

TERM=xterm-color /opt/bin/screen

Screen commands:

  • Ctrl-a Ctrl-d  = detach from screen
  • screen -r = re-attach to screen
  • Ctrl-a Ctrl-\ = kill session and terminate

Loads more command on the above screen page

Posted in Code, Software | Leave a comment

FFMPEG to crop MP3

Using ffmpeg to crop a file is fast and efficient if you know the time positions to crop. I used VLC to identify the positions (my version of vlc would not crop – sad face).

fmpeg -i input-file.mp3 -ss 6:40:00 -to 10:29:00 -c copy output-file.mp3

-ss = start time in hh:mm:ss
-to = end time in hh:mm:ss
Posted in Code | Tagged | Leave a comment

Finding devices on local network

Run the following command on a UNIX based machine:

ping -c 3 192.168.1.255 > /dev/null; arp -a

The first command pools devices and the second outputs the known devices on the network

Posted in Code | Tagged | Leave a comment