How to...



  • How to combine characters with unicode diacritical marks and print them out in Perl.

    Perl code must contain:

    use open qw(:std :utf8);
    

    To combine the character with the mark you have to use the 3 digits following the 0x0 prefix in the first column of the table below. You code it in the following way:

    print "A\x{302}\n";
    

    will print out:

    Multiple marks can be used:

    print "A\x{302}\x{32A}\n";
    

    Diacritical Marks Table:

    
    Position	Decimal	Name	Appearance
    0x0300	768	COMBINING GRAVE ACCENT	̀
    0x0301	769	COMBINING ACUTE ACCENT	́
    0x0302	770	COMBINING CIRCUMFLEX ACCENT	̂
    0x0303	771	COMBINING TILDE	̃
    0x0304	772	COMBINING MACRON	̄
    0x0305	773	COMBINING OVERLINE	̅
    0x0306	774	COMBINING BREVE	̆
    0x0307	775	COMBINING DOT ABOVE	̇
    0x0308	776	COMBINING DIAERESIS	̈
    0x0309	777	COMBINING HOOK ABOVE	̉
    0x030A	778	COMBINING RING ABOVE	̊
    0x030B	779	COMBINING DOUBLE ACUTE ACCENT	̋
    0x030C	780	COMBINING CARON	̌
    0x030D	781	COMBINING VERTICAL LINE ABOVE	̍
    0x030E	782	COMBINING DOUBLE VERTICAL LINE ABOVE	̎
    0x030F	783	COMBINING DOUBLE GRAVE ACCENT	̏
    0x0310	784	COMBINING CANDRABINDU	̐
    0x0311	785	COMBINING INVERTED BREVE	̑
    0x0312	786	COMBINING TURNED COMMA ABOVE	̒
    0x0313	787	COMBINING COMMA ABOVE	̓
    0x0314	788	COMBINING REVERSED COMMA ABOVE	̔
    0x0315	789	COMBINING COMMA ABOVE RIGHT	̕
    0x0316	790	COMBINING GRAVE ACCENT BELOW	̖
    0x0317	791	COMBINING ACUTE ACCENT BELOW	̗
    0x0318	792	COMBINING LEFT TACK BELOW	̘
    0x0319	793	COMBINING RIGHT TACK BELOW	̙
    0x031A	794	COMBINING LEFT ANGLE ABOVE	̚
    0x031B	795	COMBINING HORN	̛
    0x031C	796	COMBINING LEFT HALF RING BELOW	̜
    0x031D	797	COMBINING UP TACK BELOW	̝
    0x031E	798	COMBINING DOWN TACK BELOW	̞
    0x031F	799	COMBINING PLUS SIGN BELOW	̟
    0x0320	800	COMBINING MINUS SIGN BELOW	̠
    0x0321	801	COMBINING PALATALIZED HOOK BELOW	̡
    0x0322	802	COMBINING RETROFLEX HOOK BELOW	̢
    0x0323	803	COMBINING DOT BELOW	̣
    0x0324	804	COMBINING DIAERESIS BELOW	̤
    0x0325	805	COMBINING RING BELOW	̥
    0x0326	806	COMBINING COMMA BELOW	̦
    0x0327	807	COMBINING CEDILLA	̧
    0x0328	808	COMBINING OGONEK	̨
    0x0329	809	COMBINING VERTICAL LINE BELOW	̩
    0x032A	810	COMBINING BRIDGE BELOW	̪
    0x032B	811	COMBINING INVERTED DOUBLE ARCH BELOW	̫
    0x032C	812	COMBINING CARON BELOW	̬
    0x032D	813	COMBINING CIRCUMFLEX ACCENT BELOW	̭
    0x032E	814	COMBINING BREVE BELOW	̮
    0x032F	815	COMBINING INVERTED BREVE BELOW	̯
    0x0330	816	COMBINING TILDE BELOW	̰
    0x0331	817	COMBINING MACRON BELOW	̱
    0x0332	818	COMBINING LOW LINE	̲
    0x0333	819	COMBINING DOUBLE LOW LINE	̳
    0x0334	820	COMBINING TILDE OVERLAY	̴
    0x0335	821	COMBINING SHORT STROKE OVERLAY	̵
    0x0336	822	COMBINING LONG STROKE OVERLAY	̶
    0x0337	823	COMBINING SHORT SOLIDUS OVERLAY	̷
    0x0338	824	COMBINING LONG SOLIDUS OVERLAY	̸
    0x0339	825	COMBINING RIGHT HALF RING BELOW	̹
    0x033A	826	COMBINING INVERTED BRIDGE BELOW	̺
    0x033B	827	COMBINING SQUARE BELOW	̻
    0x033C	828	COMBINING SEAGULL BELOW	̼
    0x033D	829	COMBINING X ABOVE	̽
    0x033E	830	COMBINING VERTICAL TILDE	̾
    0x033F	831	COMBINING DOUBLE OVERLINE	̿
    0x0340	832	COMBINING GRAVE TONE MARK	̀
    0x0341	833	COMBINING ACUTE TONE MARK	́
    0x0342	834	COMBINING GREEK PERISPOMENI	͂
    0x0343	835	COMBINING GREEK KORONIS	̓
    0x0344	836	COMBINING GREEK DIALYTIKA TONOS	̈́
    0x0345	837	COMBINING GREEK YPOGEGRAMMENI	ͅ
    0x0346	838	COMBINING BRIDGE ABOVE	͆
    0x0347	839	COMBINING EQUALS SIGN BELOW	͇
    0x0348	840	COMBINING DOUBLE VERTICAL LINE BELOW	͈
    0x0349	841	COMBINING LEFT ANGLE BELOW	͉
    0x034A	842	COMBINING NOT TILDE ABOVE	͊
    0x034B	843	COMBINING HOMOTHETIC ABOVE	͋
    0x034C	844	COMBINING ALMOST EQUAL TO ABOVE	͌
    0x034D	845	COMBINING LEFT RIGHT ARROW BELOW	͍
    0x034E	846	COMBINING UPWARDS ARROW BELOW	͎
    0x0360	864	COMBINING DOUBLE TILDE	͠
    0x0361	865	COMBINING DOUBLE INVERTED BREVE	͡
    0x0362	866	COMBINING DOUBLE RIGHTWARDS ARROW BELOW	͢
    


  • How to change ownership of a topic/first post in NodeBB:

    • Login to mongo and select the nodebb db:
    mongo --port 27017
    use nodebb
    
    
    • Find the object containing the title of the Topic and note down the "mainPid" value of the first post (49 in the example below):
    > db.objects.find({"title":"Party"},{"content":0}).pretty()
    
    {
    	"_id" : ObjectId("5ce891520ff514295e68ba97"),
    	"_key" : "topic:32",
    	"tid" : 32,
    	"uid" : 18,
    	"cid" : 19,
    	"mainPid" : "49",
    	"title" : "Party",
    	"slug" : "32/party",
    	"timestamp" : 1558745426311,
    	"lastposttime" : 1559511732448,
    	"postcount" : 3,
    	"viewcount" : 19,
    	"locked" : 0,
    	"deleted" : 0,
    	"pinned" : 0,
    	"thumb" : "",
    	"teaserPid" : 72
    }
    {
    	"_id" : ObjectId("5cf0b04e60bb27abedd56188"),
    	"_key" : "event:821",
    	"type" : "post-purge",
    	"uid" : 18,
    	"pid" : "60",
    	"ip" : "137.154.34.129",
    	"tid" : 32,
    	"title" : "Party",
    	"timestamp" : 1559277646867,
    	"eid" : 821
    }
    
    • Find the "uid" of the user you wish to change ownership to (19 in the example below):
    > db.objects.find({"username":"Harry"}).pretty()
    
    {
    	"_id" : ObjectId("5cf4420b60bb27abedd56383"),
    	"_key" : "user:19",
    	"username" : "Harry",
    	"userslug" : "harry",
    	"email" : "harry@harry.com",
    	"joindate" : 1559511563818,
    	"lastonline" : 1559512762482,
    	"picture" : "",
    	"fullname" : "harry_mcboatface",
    	"location" : "",
    	"birthday" : "",
    	"website" : "",
    	"signature" : "",
    	"uploadedpicture" : "",
    	"profileviews" : 2,
    	"reputation" : 0,
    	"postcount" : 3,
    	"topiccount" : 0,
    	"lastposttime" : 1559512083251,
    	"banned" : 0,
    	"status" : "online",
    	"gdpr_consent" : 0,
    	"acceptTos" : 0,
    	"uid" : 19,
    	"ldapid" : 4028644545,
    	"rss_token" : "340dc97c-0586-4ecd-8584-2241d106ce03"
    }
    
    
    • Use the "uid" value from above (19) to update the "cid" and "uid" values of the topic
    > db.objects.update({ "title":"Party" },{$set: { "cid" : 19 }})
    > db.objects.update({ "title":"Party" },{$set: { "uid" : 19 }})
    
    • Use the "uid" value from above (19) to update the first post from above ("pid" 49)
    > db.objects.update({ "pid": 49 },{$set: { "uid" : 19 }})
    
    • If you want to be very thorough you can update the uid of the post edit history. Find all edit 'eid' values shown after running the very first command in this post :
    db.objects.find({"title":"Party"},{"content":0}).pretty()
    

              and update their uid:

    db.objects.update({ "eid": 821 },{$set: { "uid" : 19 }})
    
    • You then change the uid of all posts in the topic by inspecting the html of each post for the uid in your browser (eg. in chrome on windows right-click the post and choose inspect from the pull down menu):

    find_pid.jpg

    • Then use the following code in mongo to update the uid for that pid:
    db.objects.update({ "pid": 299 },{$set: { "uid" : 19 }})
    
    
    • You need to rebuild and restart the database using the Admin Control Panel (ACP) for the changes to take effect.


  • How to view Microsoft Word documents online in NodeBB:

    [normal link](/assets/uploads/files/1559590085004-test-word-document.docx)
    
    [viewable link](https://view.officeapps.live.com/op/view.aspx?src=https%3A%2F%2Flinks.sharezomics.com%2Fassets%2Fuploads%2Ffiles%2F1559590085004-test-word-document.docx)
    

    normal link

    viewable link



  • How to rip/copy DVD's to your hard drive:

    Method 1 (NB. Had problems with out of sync voices with this one)

    • Download and install VLC media player.

    • Run VLC media player.

    • Insert DVD.

    • In VLC media player, click Media, and then click Convert / Save... The Open Media window opens.

    • Tick 'No disc menus' and raise the Title number to 1

    vlc1.jpg

    • Click Convert / Save.

    • Click the additional settings button:

    vlc2.jpg

    • Choose Ogg/Ogm encapsulation:

    vlc3.jpg

    • Choose MPEG-4 Video codec:

    vlc4.jpg

    • Click save and provide a Destination file name
    • Click Start

    Method 2 (better)



  • How to organise NodeBB sub-categories into columns with CSS:

    .category-children .category-children-item {
        float: left ;
        width: 20em ;
    }
    




  • How to convert a docker image to a singularity image:

    docker run \
      -v /var/run/docker.sock:/var/run/docker.sock \
      -v D:\host\path\where\to\output\singularity\image:/output \
      --privileged -t --rm \
      filo/docker2singularity \
      ubuntu:14.04
    

    Replace D:\host\path\where\to\output\singularity\image with a path in the host filesystem where your Singularity image will be created. Replace ubuntu:14.04 with the docker image name you wish to convert (it will be pulled from Docker Hub if it does not exist on your host system).

    You can read more and submit issues or patches at https://github.com/chrisfilo/docker2singularity



  • How to filter mapped/unmapped fastq reads:

    • get all the reads where both mapped:
    samtools view -F 12 bothEndsMapped.bam
    
    • get all the reads that did not map, but whose mate mapped:
    samtools view  -F 4 -f 8 onlyThisEndMapped.bam
    
    • get all the reads that mapped, but whose mates did not:
    samtools view -F 8 -f 4 onlyThatEndMapped.bam
    
    • get all the reads where neither one mapped:
    samtools view -f 12 neitherEndMapped.bam
    


  • How to write nodejs async/await code:

    // With function declaration
    async function myFn() {
      // await ...
    }
    // With arrow function
    const myFn = async () => {
      // await ...
    }
    

    Source



  • How to display the contents of a circular JSON object in nodejs:

    Method1:

    		const getCircularReplacer = () => {
    		  const seen = new WeakSet();
    		  return (key, value) => {
    		    if (typeof value === "object" && value !== null) {
    		      if (seen.has(value)) {
    		        return;
    		      }
    		      seen.add(value);
    		    }
    		    return value;
    		  };
    		};
    
    		var string=JSON.stringify(circularJSONobject, getCircularReplacer());
    		console.log(string);
    
    

    Method 2:

    var util = require('util'); //a core nodejs function but it has to be imported
    console.log(util.inspect(circularJSONobject));
    


  • How to create post buttons that look like links:

    css:

      .link-button {
        background: none;
        border: none;
        color: #337ab7;
        cursor: pointer;
        font-size: 19px;
        font-weight: 400;
        font-family: 'Lato', sans-serif;
      }
      .link-button:focus {
        outline: none;
      }
      .link-button:active {
        color:red;
      }
      .link-button:hover {
        text-decoration: underline;
        filter: brightness(65%);
      }
    

    html:

    <form method="post" action="https://mics.com/index" class="inline">
    <button type="submit" name="submit_name" value="name" class="link-button">link display text</button>
    </form>
    


  • How to display line numbers for pasted code in NodeBB:

    This is from here.

    NB. (This isn't working for me)

    Put this in your custom header (ACP -> Appearance -> Custom HTML & CSS -> Custom Header):

    <script>
    require(['highlight'], function (hljs) {
      require([
        'https://cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/1.1.0/highlightjs-line-numbers.min.js'
      ], function () {
        $(window).on('load action:ajaxify.end', function () {
          setTimeout(function () {
            hljs.initLineNumbersOnLoad();
          }, 100);
        });
      });
    });
    </script>
    

    NB. The contents of 'highlightjs-line-numbers.min.js' are:

    !function(e){"use strict";function t(){"complete"===document.readyState?n():e.addEventListener("DOMContentLoaded",n)}function n(){try{var e=document.querySelectorAll("code.hljs");for(var t in e)e.hasOwnProperty(t)&&r(e[t])}catch(n){console.error("LineNumbers error: ",n)}}function r(e){if("object"==typeof e){var t=e.parentNode,n=o(t.textContent);if(n>1){for(var r="",c=0;n>c;c++)r+=c+1+"\n";var l=document.createElement("code");l.className="hljs hljs-line-numbers",l.style["float"]="left",l.textContent=r,t.insertBefore(l,e)}}}function o(e){if(0===e.length)return 0;var t=/\r\n|\r|\n/g,n=e.match(t);return n=n?n.length:0,e[e.length-1].match(t)||(n+=1),n}"undefined"==typeof e.hljs?console.error("highlight.js not detected!"):(e.hljs.initLineNumbersOnLoad=t,e.hljs.lineNumbersBlock=r)}(window);
    


  • How to cycle/loop through an object in javascript:

    for (var key in req.body) {
        if (key in req.body) {
            console.log(req.body[key]);
        }
    }
    


  • %(#ffffff)[How to publish a package with npm:]

    *Sign in with npm login:

    npm login
    

    You’ll be prompted to enter your username, password, and email address.

    *Create a folder named how-to-publish-to-npm:

    mkdir how-to-publish-to-npm
    

    *Navigate into the folder:

    cd how-to-publish-to-npm
    

    *Begin the project with the npm init command:

    npm init
    

    This command runs you through a few questions and creates a package.json file for you at the end. This package.json file contains the bare necessities you need to publish your project. (Feel free to skip questions that don’t make sense).

    *The final step is to publish your package with the npm publish command:

    npm publish
    


  • How to set permissions in linux with chmod:

    chmod 600 {filespec}	You can read and write; the world can't. Good for files.
    chmod 700 {filespec}	You can read, write, and execute; the world can't. Good for scripts.
    chmod 644 {filespec}	You can read and write; the world can only read. Good for web pages.
    chmod 640 {filespec}	You can read and write; group can read, the world can't do anything.Good for group project..
    chmod 755 {filespec}	You can read, write, and execute; the world can read and execute. Good for programs you want to share, and your public_html directory.
    chmod 750 {filespec}	You can read, write, and execute; the group can read and execute, the world can't do anything. Good for programs you want to share within group.
    


  • How to install WebODM on Windows 10 home:

    • Download Docker Toolbox and install it as an administrator. (You may need to uninstall VirtualBox first.)
    • Launch Docker Quickstart Terminal as an administrator. Note down the IP address shown below the whale.
    
                            ##         .
                      ## ## ##        ==
                   ## ## ## ## ##    ===
               /"""""""""""""""""\___/ ===
          ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
               \______ o           __/
                 \    \         __/
                  \____\_______/
    
    docker is configured to use the default machine with IP 192.168.99.100
    For help getting started, check out the docs at https://docs.docker.com
    
    
    • Download WebODM with Git and start it:
    git clone https://github.com/OpenDroneMap/WebODM --config core.autocrlf=input --depth 1
    cd WebODM
    sh ./webodm.sh start
    
    • Navigate to port 8000 of the IP address recorded in the first step:
    http://192.168.99.100:8000
    
    • It is advisable to resize the VM associated with WebODM.
    cd "C:\Program Files\Oracle\VirtualBox"
    ./VBoxManage clonemedium disk --format VDI "C:\Users\username\.docker\machine\machines\default\disk.vmdk" "C:\Users\username\.docker\machine\machines\default\disk.vdi"
    
    ./VBoxManage modifyhd "C:\Users\username\.docker\machine\machines\default\disk.vdi" --resize 100000
    

    After resizing you will need to use a GParted VM to resize the partitions.

    • If you want to stop WebODM then use the command:
    sh ./webodm.sh down
    
    • To completely stop WebODM you will have to also stop the VirtualBox VBoxHeadless process using the Windows task manager


  • How to pipe output from a shell command to Perl to a shell command within a Perl script:

    $com='samtools view -h '.$infile;
    my $zom='samtools view -bS - > q64converted.bam';
    open(SBAM, "$com|");
    open SBOUT, "|$zom";
    while (<SBAM>){
    	print SBOUT "$_";
    }
    close(SBAM);
    close SBOUT;
    


  • How to find out which pages are visited according to user country in Google Analytics:

    how to view visited pages by country.jpg



  • How to horizontally split a file view in sublime text editor:

    Split the view by using View -> Layout -> Rows: 2. Then select Row 1 and go to File -> New View into File. It will open second tab with the same file. Then you can drag that tab to the Row 2.



  • How to push a docker image to Docker Hub:

    • You need to have an account on Docker Hub. In this example the account is named 'ning'.
    • The image must be built so that the account name is within the image name

    Eg. for docker command:

    docker tag nextflow_docker:202004201512  ning/nextflow_docker:202004201512
    
    • For a docker-compose file:
    version: '3'
    services:
      nextflow_docker:
        build: ./nextflow_docker
        image: ning/nextflow_docker:latest
    
    • Then you need to push:
    docker logout
    docker login
    #login with your username and password (if you are on ubuntu you can ignore password keyring (agree but dont enter a password)
    #NB. If you are on ubuntu and get the error message "Error calling StartServiceByName for org.freedesktop.secrets: Timeout was reached" , try the following command "sudo apt remove gnome-keyring golang-docker-credential-helpers"
    docker push ning/nextflow_docker:latest
    

Log in to reply
 

Powered by ShareZomics