SCP

Examples

Copy the file “foobar.txt” from a remote host to the local host

$ scp your_username@remotehost.edu:foobar.txt /some/local/directory

Copy the file “foobar.txt” from the local host to a remote host

$ scp foobar.txt your_username@remotehost.edu:/some/remote/directory

Copy the directory “foo” from the local host to a remote host’s directory “bar”

Continue reading SCP

Advertisements

Measuring elapsed time

Windows

#include <windows.h> 
...   
using namespace std;

int main() {
    LARGE_INTEGER f;      // ticks per second
    LARGE_INTEGER t1, t2; // ticks
    double dt;

    QueryPerformanceFrequency(&f);
    QueryPerformanceCounter(&t1);
    // ... do stuff
    QueryPerformanceCounter(&t2);
    
    dt = (t2.QuadPart-t1.QuadPart)*1000.0/f.QuadPart;
    cout << elapsedTime << " ms.\n";

    return 0;
}

Linux

#include <sys/time.h>
...
using namespace std;

int main() {
    struct timeval t1, t2;
    double dt;
    
    gettimeofday(&t1, NULL);
    // ... do stuff   
    gettimeofday(&t2, NULL);

    // sec to ms
    dt = (t2.tv_sec - t1.tv_sec) * 1000.0; 
     
    // us to ms
    dt += (t2.tv_usec - t1.tv_usec) / 1000.0;   
    cout << dt << " ms.\n";

    return 0;
}

Bash

$ time ./myprogram

Bash (in script)

start=$SECONDS
# ... do stuff
end=$SECONDS
dt=$(( end - start ))
echo "stuff took $dt seconds to complete"

 

References:

https://stackoverflow.com/questions/14682824/measuring-elapsed-time-in-linux-for-a-c-program

https://stackoverflow.com/questions/2150291/how-do-i-measure-a-time-interval-in-c

My Favorite android apps (free)

Since HTTP links change frequently, there are no direct links included in the list below.

All apps will be easily found if searched on google play or google lucky.

Here is the list (all of them free):

Basic Setup

  1. TokikoFree
  2. QuickDial Free
  3. Google Keep
  4. Google Authenticator
  5. First Aid
  6. B1 archiver

Very Useful Utilities

  1. CamScanner
  2. Flash light Ad Free
  3. Pi Scientific Calculator
  4. Ultimate Stopwatch

Wifi

  1. WiFi Ruler
  2. Wifi Analyzer
  3. Advanced Spectrum Analyzer
  4. Spectroid

Multimedia

  1. Shazam
  2. SoundHound
  3. Backgrounds

System tools

  1. Advanced Task killer
  2. Permissions Explorer
  3. Sensors Multitool
  4. IP tools

Consumer

  1. Viber
  2. Viber Contact Photos
  3. Forky
  4. Athens Book

 

 

Google docs – send a doc monthly via email

Here is a small script you can attach to a document on Google docs.

Whenever run, it will attach the file and send it to you via e-mail.

function monthlyBackup() {
 var formattedMonth = Utilities.formatDate(new Date(), "GMT", "MM");
 var formattedDate = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd' 'HH:mm:ss");
 var name = SpreadsheetApp.getActiveSpreadsheet().getName() + " backup " + formattedDate;
 
 
 var ssID = SpreadsheetApp.getActiveSpreadsheet().getId();
 var sheetName = SpreadsheetApp.getActiveSpreadsheet().getName();
 //var email = Session.getUser().getEmail();
 var email = "XXX@XXX.XXX";
 var subject = SpreadsheetApp.getActiveSpreadsheet().getName() + " backup at " + formattedDate;
 var body = "This is automated backup from google docs :)";
 
 var requestData = { "method": "GET", "headers":{"Authorization":"Bearer "+ScriptApp.getOAuthToken()} };
 
 var url = "https://docs.google.com/spreadsheets/d/"+ ssID + "/export?format=ods&id="+ssID;
 
 var result = UrlFetchApp.fetch(url , requestData); 
 var contents = result.getContent();
 
 var attachedFilename = sheetName + " " + formattedMonth + ".ods";
 
 MailApp.sendEmail(email, subject ,body, {attachments:[{fileName:attachedFilename, content:contents, mimeType:"application//x-vnd.oasis.opendocument.spreadsheet"}]}); 
}

For more MIME types read this article:

https://developers.google.com/drive/v3/web/integrate-open

If you want to add a menu item you can also the following code:

function onOpen() {
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var menuEntries = [ {name: "Send Email", functionName: "monthlyBackup"}];
 ss.addMenu("Scripts", menuEntries);
};

 

References:

http://igoogledrive.blogspot.gr/2012/08/send-google-spreadsheet-sheet-to-email.html

https://webapps.stackexchange.com/questions/60445/send-an-email-with-attachment-using-google-apps-script

https://developers.google.com/drive/v3/web/integrate-open

Pointer arithmetic to void* (uintptr_t)

The link below is a very important one regarding pointer arithmetic, a subject that frequently is being taught incorrectly in many universities:

https://stackoverflow.com/questions/3523145/pointer-arithmetic-for-void-pointer-in-c

The best way for general arithmetic on pointers for most architectures is to use the uintptr_tΒ  data type whenever available.

Cast the pointer to uintptr_t and make any arithmetic operation you want. Then cast the uintptr_t back to the type of the pointer you want:

void calculateModulo(char *address) { 
    uintptr_t x = (uintptr_t)address; 
    x = x % 4;
    char * resultingaddress = (char*) x;
    ....
}

 

Upgrade to gcc 6.3+ in Ubuntu

To upgrade gcc to gcc6 use the following commands:

sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-6 -y

 

To set the new gcc as default use the following:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5

Once you have executed the previous command, g++ may not be available.

So you can execute the following to create a link:

sudo ln -s /usr/bin/g++-5 /usr/bin/g++

 

Syntax highlighing in Moodle

The main idea is that we need syntax highlighting to quiz questions.

Here are the requirements:

  1. a plugin that is updated frequently, preferable by more than 1 person.
  2. support for syntax highlighting to as many languages as possible, not only in editing mode within the editor but in the view mode of questions, pages etc.
  3. it has to be free.
  4. it is better that it is accessible from the buttons of the editor so that it is easily accessible from students who want to create quiz content.
  5. it should support moodle 3.3+

Continue reading Syntax highlighing in Moodle

Personal portal to the Internet