Back to Top

How to set the umask for SFTP so file uploads are 644 permissions and folder permissions are 755

The default SFTP file and folder umask permissions can be custom changed in the /etc/ssh/sshd_config file

 

Modify /etc/ssh/sshd_config and search for the line with sftp like the following

 

Subsystem sftp /usr/libexec/openssh/sftp-server

to
Subsystem sftp /usr/libexec/openssh/sftp-server -u 0022

and restart sshd with

/scripts/restartsrv_sshd
Posted in Cpanel |

cmake uncompressing error on exfat formatted discs

Found a bug in windows cmake when trying to recompile opencv – apparently it cannot reset the file date stamp correctly, so fails to uncompress the source zip, and the whole generation process crashes..

I fixed it in the opencv source by replacing this line in the OpenCVDownload.cmake file (under the cmake source folder) by using the 7zip software instead of default unzipper..

 

execute_process(COMMAND "${CMAKE_COMMAND}" -E tar xzf "${CACHE_CANDIDATE}"

with

 

execute_process(COMMAND 7z x "${CACHE_CANDIDATE}"

and making sure the path is set to the 7zip executable 7z.exe

Posted in Other |

Open File Dialog Script In Unity

C# Unity Script (but excluding any project namespace) for showing a file dialog in Unity for selecting a .Sch train schedule file name – source taken from various websites but linked it together for a working script example here. Acknowledging Astiolo.


using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using System;
using System.Runtime.InteropServices;



   [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]

    public class OpenFileName {
        public int      structSize = 0;
        public IntPtr   dlgOwner = IntPtr.Zero;
        public IntPtr   instance = IntPtr.Zero;
        public String   filter = null;
        public String   customFilter = null;
        public int      maxCustFilter = 0;
        public int      filterIndex = 0;
        public String   file = null;
        public int      maxFile = 0;
        public String   fileTitle = null;
        public int      maxFileTitle = 0;
        public String   initialDir = null;
        public String   title = null;
        public int      flags = 0;
        public short    fileOffset = 0;
        public short    fileExtension = 0;
        public String   defExt = null;
        public IntPtr   custData = IntPtr.Zero;
        public IntPtr   hook = IntPtr.Zero;
        public String   templateName = null;
        public IntPtr   reservedPtr = IntPtr.Zero;
        public int      reservedInt = 0;
        public int      flagsEx = 0;
    }
     
    public class DllTest {
        [DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
        public static extern bool GetOpenFileName([In, Out] OpenFileName ofn);
        public static bool GetOpenFileName1([In, Out] OpenFileName ofn) {
            return GetOpenFileName(ofn);
        }
    }	

public class TimerClock : MonoBehaviour
{



	void Start () 
	{

OpenFileName ofn = new OpenFileName();
            ofn.structSize = Marshal.SizeOf(ofn);
            ofn.filter = "Train Sch Files\0*.sch\0\0";
            ofn.file = new string(new char[256]);
            ofn.maxFile = ofn.file.Length;
            ofn.fileTitle = new string(new char[64]);
            ofn.maxFileTitle = ofn.fileTitle.Length;
            ofn.initialDir = UnityEngine.Application.dataPath;
            ofn.title = "Upload Train Schedule";
            ofn.defExt = "SCH";
            ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR
            if(DllTest.GetOpenFileName(ofn)) {
                Debug.Log( "Selected file with full path: {0}"+ofn.file );
            }


	}

	void Update ()
	{
		



	}
}


Posted in Unity |

Bulk remove a category from posts

Almost unbelievably in a default wordpress install there is no way to bulk remove a category from posts via the dashboard, you can add them in the bulk edit mode, but not batch remove them from posts.

 

Only way I have found to be able to do it is as follows..

 

(1) Find the ID of the category you wish to remove posts from eg in this example category Diet has an id of 28281 – found by hovering over the edit tag and noting the tag_ID bit of the url  bit ?taxonomy=category&tag_ID=28281&post_type=post&wp_http_referer=%2Fwp-admin%2Fedit-tags.php%3Ftaxonomy%3Dcategory

 

 

(2) Add the following code to you themes functions file replacing {category_id} with the category id (numeric) found above in part 1 eg 28281

 

add_action( 'init', function()
{
    
    $args = [
        'posts_per_page' => -1, 
        'cat'            => {category_id}, // Category ID for category you wish to remove posts from 
        'fields'         => 'ids', 
            ];
    $found_posts = get_posts( $args );

    if ( !$found_posts ) return;

    foreach ( $found_posts as $id )
        wp_remove_object_terms(
            $id, // Post ID
            {category_id}, 
            'category' 
        );
}, PHP_INT_MAX );

3) Then load the page view to make sure the above code is triggered, then go back to dashboard and check that all posts have been removed from your selected category.

4) Finally when happy all posts have been removed from the category, re-edit your themes functions file, and remove the code you added in part 2 above.

5) Optional – delete empty category, if you wish.

Posted in Wordpress |

Setting The Path To Home Directory In PHP

Got two methods, one for WordPress and another for other general PHP scripts.

 

WordPress; Simply use the constant ABSPATH eg file(ABSPATH.”some-other-folder/some-file.txt”); – it returns the path to where wp-config.php is located for the current wordpress install.

 

General: Can use the following to obtain the home or root folder.. $doc_root = preg_replace(“!${_SERVER[‘SCRIPT_NAME’]}$!”, ”, $_SERVER[‘SCRIPT_FILENAME’]);

 

Note: $doc_root won’t include an end / – so on any additional file/path one will need to be added.

 

Posted in PHP, Wordpress |

Splitting a video using linux command line

Best way I have found to split a mp4 video on linux is to use

avconv -ss {start time in seconds} -i {source mp4} -t {duration in seconds}  -vcodec copy -acodec copy -metadata track="{track number}" "{output mp4}" 

where
{start time in seconds} is the time from the beginning of the video in seconds to set the start marker of clip eg 0 for the video beginning

{duration in seconds} is the duration from the marker start to set the end marker of clip eg 200 for 200 seconds from the beginning of the video

{source mp4} is the path to the source mp4 video eg source.mp4

{track number} is the integer current track number eg 1,2,3 etc

{output mp4} is the path to the output mp4 split video eg part-1.mp4

Easy to adapt for a shell script or as I use a php wrapper script.

Can use ffmpeg instead but I don’t find the video quality very good.

 

 

Posted in Misc Topics |

How to Safely Enable SVG File uploading in wordpress

This code snippet for wordpress allows the importing of .svg files which by default are restricted on security grounds.. would only use if you know you are using sanitized .svg files and/or a single admin user of your website.

function cc_mime_types($mimes) {
 $mimes['svg'] = 'image/svg+xml';
 return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');

should be added to the bottom of theme functions.php file.

Posted in Wordpress |

Disabling power throttling on windows 10

Disabling power throttling seems to be easiest way to solve dynamic frequency scaling problem.

Here’s how to do it in Registry Editor.

  1. Open Run dialog box by pressing Start + R. Or typing regedit into search box.
  2. Type regedit into the text box and hit Enter to run software.
  3. Click Yes in the User Account Control window.
  4. Expand HKEY_LOCAL_MACHINE, SYSTEM, CurrentControlSet, and Control in order.
  5. Right click on the Power folder.
  6. Choose New from the context menu and select Key from submenu.
  7. Name the new key as PowerThrottling and hit Enter.
  8. Right click on PowerThrottling.
  9. Choose New from the context menu and select DWORD (32-bit) Value from submenu.
  10. Name it as PowerThrottlingOff and hit Enter.
  11. Double click on PowerThrottlingOff to edit.
  12. Change the Value data from 0 to 1 and click OK.

Posted in CPU |

Installing OpenCV 4.x.x for for C++, Windows 7 or 10, Using Code::Blocks, TDM-GCC-64

This is a quick step-by-step guide for installing opencv

1) Backup your existing opencv build files

2) Install Code::Blocks http://www.codeblocks.org/downloads/26 select current version codeblocks-17.12-setup.exe

3) Install TDM-GCC – making sure the 64-bit version is selected http://tdm-gcc.tdragon.net/download

Note: compiler binary file path will be automatically added to your pc’s path environment.

4) Download the source of OpenCV 4.x.x from https://opencv.org/releases.html as a zip file

Create folders:

C:\opencv\source\
C:\opencv\build\

Unzip the downloaded zip file in the source folder c:\opencv\source\ just created, so you get a folder like C:\opencv\source\opencv-4.x.x

5) Install CMake (uninstall any previous version as major changes made) https://cmake.org/download/

6) Setup to build the binaries:

Open cmake, set source path to C:\opencv\source\opencv-4.x.x and binary path to C:\opencv\build.

Click Configure

Choose CodeBlock—MinGW Makefiles as compiler.

After configuring, options will appear in red, some of these need disabling..

Disable: WITH_MSMF, set ENABLE_PRECOMPILED_HEADERS=OFF, WITH_IPP=OFF WITH_TBB=OFF (these options are for visual studio)

WITH_OPENCL_D3D11_NV=OFF

Note: you can use cmake’s search tool to search for these option eg. enter IPP to disable WITH_IPP etc

Next select/click the Generate button.

A codeblocks project file (opencv.cbp) will be made in C:\opencv\build

7) Now build the binaries:

Open the opencv.cbp file in code::blocks

Go to “settings”, choose “compiler” and click “Toolchain executable”. In the “compiler’s installation directory” field choose C:\TDM-GCC-64\bin (binary folder of the TDM compiler installed earlier)

Set the following:

c compile: gcc.exe
c++ compiler: g++.exe (but see note below on handling C++ 11 ISO errors)
Linker for dynamic libs: g++.exe
linker for static libs: ar.exe

Then use Select build > select target > install

Then press the build button to start the building of the binaries – this can take hours to process.

Add C:\opencv\build\install\x64\mingw\bin to the system environment path

8) Now setup up code::blocks to compile an opencv program.

Go to settings -> compiler. Select “search directories” and in the “compiler” tab chose the followings:

C:\opencv\build\install\include
C:\opencv\build\install\include\opencv2

Select “Linker” tab and add “C:\opencv\build\install\x64\mingw\lib”

Go to “Linker Settings” and add all the libraries from “C:\opencv\build\install\x64\mingw\lib” folder so it looks like this..

9) Final configuration – on opencv 4.0.1 you might get a C++ 11 ISO error on compiling, so I recommend just adding this to the C++ compiler option under “Toolchain executable”. In the “compiler’s installation directory”:

c++ compiler: g++.exe -std=c++11

Edit your cpp code (remember to setup as console applications). Then build, then run.. and all been well your script will run on opencv (note many constant values have changed between opencv releases, so highly likely you will need to change your code)

Hope this is useful.

Posted in Other |

Getting phantomjs working on CentOS servers

If anyone else gets the following error on trying to use the 64 bit version of phantomjs binary..

./phantomjs: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
yum install zlib.i686

Try using yum to install the following packages..

yum -y install glibc.i686
yum install zlib.i686
yum install fontconfig freetype freetype-devel fontconfig-devel libstdc++
yum install libfontconfig.so.1
yum install libstdc++.so.6

Worked for myself.

Posted in Misc Topics |