Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

12 March 2017

Local port forward

How to connect on a remote service as if it is existed on your localhost

ssh -L <The New Port on your machine>:localhost:<The original port on the remote machine> <Remote machine user name>@<The remote machine>

Example for sql on a linux machine on port 1433:

ssh -L 1433:localhost:1433 username@my-linux-machine

http://blog.trackets.com/2014/05/17/ssh-tunnel-local-and-remote-port-forwarding-explained-with-examples.html

30 July 2016

Hide and Unhide Plex Media Servers Libraries

Plex media server is a famous media server, I use it at home to set local media server for myself and family.

However, to be able to hide some Libraries is not straightforward,  as it is not supported by the app itself, and there's a plugin that allows you to do so for 1 Library for free and pay for the others (It called Lock for Plex).

I used this extension and find out how it works, and I hacked it and be able to hide more than one Library.

How "Lock for Plex" work is by updating the database used by Plex.

It uses two bash files, one for lock and the other for unlock:


Plex Media Server/Plug-ins/Lock_for_Plex.bundle/Contents/Resources/lock_support/lock.sh

Plex Media Server/Plug-ins/Lock_for_Plex.bundle/Contents/Resources/lock_support/unlock.sh

Here's the content for myself after I've been modified on this file:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
cat lock.sh
#!/bin/bash


lockplex="UPDATE metadata_items SET metadata_type=20 WHERE library_section_id=2 and metadata_type=1; DELETE FROM library_sections WHERE id=2;"
lockplex2="UPDATE metadata_items SET metadata_type=4444 WHERE library_section_id=8 and metadata_type=4; DELETE FROM library_sections WHERE id=8;"

cd "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/Lock_for_Plex.bundle/Contents/Resources/lock_support/"

./sqlite3 "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" "$lockplex" 
./sqlite3 "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" "$lockplex2" 

exit;
mhewedy@probook:~$ cat unlock.sh 
#!/bin/bash

unlockplex="UPDATE metadata_items SET metadata_type=1 WHERE library_section_id=2 and metadata_type=20; INSERT OR REPLACE INTO library_sections (id,name,section_type,language,agent,scanner,created_at,updated_at,scanned_at,user_fields,uuid) VALUES (2,'English Movies',1,'en','com.plexapp.agents.imdb','Plex Movie Scanner','2016-07-03 07:27:07','2016-07-03 08:35:21','2016-07-03 08:35:21','pr%3AenableCinemaTrailers=0&pr%3AincludeInGlobal=0','c07640f7-a137-4987-95ba-c3c5850383d3');"

unlockplex2="UPDATE metadata_items SET metadata_type=4 WHERE library_section_id=8 and metadata_type=4444; INSERT OR REPLACE INTO library_sections (id,name,section_type,language,agent,scanner,created_at,updated_at,scanned_at,user_fields,uuid) VALUES (8,'TV Shows',2,'en','com.plexapp.agents.thetvdb','Plex Movie Scanner','2016-07-07 03:45:33','2016-07-07 03:45:55','2016-07-13 21:03:02','pr%3AincludeInGlobal=0','0d670ea9-0da4-4639-8f52-2fcd64f3d8c8');"

cd "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/Lock_for_Plex.bundle/Contents/Resources/lock_support/"

./sqlite3 "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" "$unlockplex" 
./sqlite3 "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db" "$unlockplex2" 

exit;

One other way to achieve the same result is to have some other disk partition and mount it on-demond.


30 May 2014

continually monitor CPU usage for a command

cmd=[m]oviecrawler;while :; do echo -ne "CPU: `ps aux | grep $cmd | awk '{print $3}'`\\r" ;  sleep 1; done

07 May 2014

Obtain the best look ever for Intellj on Linux

(1) install freetype
$ sudo apt-get install libfreetype6

(2) install infinality patch (https://launchpad.net/~no1wantdthisname/+archive/ppa)
$ sudo add-apt-repository ppa:no1wantdthisname/ppa
$ sudo apt-get update
$ sudo apt-get install fontconfig-infinality

I had to do the following afterwards:
$ sudo rm /etc/fonts/conf.avail/52-infinality.conf
$ sudo ln -s /etc/fonts/infinality/infinality.conf /etc/fonts/conf.avail/52-infinality.conf

To use Windows 7 like font rendering do the following:
$ sudo /etc/fonts/infinality/infctl.sh setstyle osx
Set USE_STYLE to "osx" in /etc/profile.d/infinality-settings.sh

(3) install font fixed OpenJDK (https://launchpad.net/~no1wantdthisname/+archive/openjdk-fontfix)
$ sudo add-apt-repository ppa:no1wantdthisname/openjdk-fontfix
$ sudo apt-get update
$ sudo apt-get install openjdk-7-jdk

To use this JDK only for IntelliJ, prepend this line to bin/idea.sh:
IDEA_JDK="/usr/lib/jvm/java-1.7.0-openjdk-amd64"

(4) JVM options
Add the following options to the .vmoptions file of IntelliJ
-Dawt.useSystemAAFontSettings=lcd
-Dswing.aatext=true

(5)
Perform a reboot

(6)
See the result with default Darcula theme in attachment.

Hope this helps someone!


Source:
http://youtrack.jetbrains.com/issue/IDEA-57233#comment=27-472038

BTW, I've tried this on Idea 13.1 on Ubuntu 14.04 and it works like a charm ... here's an screenshot ..



Display apps on unity launcher

If you have app and want to display it when search in unity launcher... you need to add an entry for it in `/usr/share/applications`

example:

/usr/share/applications$ cat idea.desktop
[Desktop Entry]
Version=13.1
Name=Intellj Idea
Exec=/home/mhewedy/disk/programs/idea-IC-135.480/bin/idea.sh
Icon=/home/mhewedy/disk/programs/idea-IC-135.480/bin/idea.png
Terminal=false
Type=Application
Actions=
Categories=Programming
Actions=Profile;Tray;
Keywords=idea;java;intellj;ide # keywords to search with to find the app, very important



That's all!

06 May 2014

Put java on your path after install jdk manually in linux

Some times, you do install your JDK manually in Linux and then you have to put `java` executables in your PATH...

You can just put $JAVA_HOME/bin in your path... or you can use `alternatives` system.

To use alternatives... so you can have multiple jdk/jre installed on the same machine and you choose among then, you will need to add them to alternatives system...

cd /path/to/java/home/bin
for f in *; do sudo update-alternatives --install /usr/bin/$f $f /usr/lib/jvm/java-8-oracle/bin/$f 0; done;


And that's all!

29 April 2014

Periodically change the background of Linux desktop

I've wrote a script that periodically change the background of your Linux desktop.

The script and installation description are on github=> bg_cycle

Have fun!

26 April 2014

Convert Jar files to executables on Linux

After finished the image-downloader, I find it very funny to use it to crawl the site to download different backgrounds!

But I find it uncomfortable if I use it as Java jar, so I needed to either wrap it in some shell script (very easy), or convert it into some shell executable, so to forget about the JAR file at all.

I found this command to convert any JAR to shell executable (instead of just wrapping it):

(echo '#!/usr/bin/java -jar'; cat blahblah.jar) > blah
(echo '#!/usr/bin/java -jar'; cat ImageDDL.jar) > imageddl; chmod +x imageddl

It is very awesome!

BTW, You can download the Linux executable from here imageddl!

23 April 2014

Install PPAs on latest Ubuntu releases

Sometimes, when you have the latest release of Ubuntu, and then try to install some PPA, you cannot install at get 404 error while executing (apt-get update)

This is because, the PPA structure requires build per each release, the following image will make it clear:


Currently we have a new Release of ubuntu (14.04) with code name Trusty Tahr, but the important part here is the first part which is "trusty", but it is not found in the PPA of "fogger app".

When you try to install this app on Ubuntu 14.04, you will get 404, file not found. So here we will talk about the solution..

Regularly, you issue the following commands to install the software from the ppa:

$ sudo add-apt-repository ppa:loneowais/fogger
$ sudo apt-get update  # here you will get the 404 error.
$ sudo apt-get install fogger # you will not be able to find the fogger to install because of the failure in the preceding step.


This is happens because when you try to add the ppa, it is added in the source list files under "trusty" which is not supported yet.
you can check the source file your self (in our case here's the source list of fogger):

$ cat /etc/apt/sources.list.d/fogger-app-authors-ppa-trusty.list 
deb http://ppa.launchpad.net/fogger-app-authors/ppa/ubuntu trusty main
deb-src http://ppa.launchpad.net/fogger-app-authors/ppa/ubuntu trusty main


The workaround to do is to make your distro point to the software of the previous ubuntu release, and this by editing the source list file to point to "saucy" instead. (notice the saucy has a release in the first PPA picture of fogger)

Let's change the source list file:

$ sudo gedit /etc/apt/sources.list.d/fogger-app-authors-ppa-trusty.list 
deb http://ppa.launchpad.net/fogger-app-authors/ppa/ubuntu saucy main
deb-src http://ppa.launchpad.net/fogger-app-autthors/ppa/ubuntu saucy main

(note we replaced "trusty" with "saucy", provided that "saucy" has a release in the PPA, if not try older version)

Now we can continue our installation:

$ sudo apt-get update
$ sudo apt-get install fogger


You should be able to install the software now. have fun!

30 August 2013

Remove all installed kde programs

sudo apt-get remove  `dpkg --get-selections | grep kde | awk '{ print $1}'`
sudo apt-get remove  `dpkg --get-selections | grep qt | awk '{ print $1}'`

19 February 2013

Get list of file descriptors used by a process in linux

In Linux, you can get a list of all file descriptors used by a running program (process). It is found under path /proc/{pid}/fd example, I've started tomcat and go to: /proc/3613/fd. output of the above directory (on my local machine):
lr-x------ 1 mhewedy mhewedy 64 Feb 19 01:15 0 -> /dev/null
l-wx------ 1 mhewedy mhewedy 64 Feb 19 01:15 1 -> /windows/Work/linuxInstallations/apache-tomcat-7.0.29/logs/catalina.out
l-wx------ 1 mhewedy mhewedy 64 Feb 19 01:15 10 -> /windows/Work/linuxInstallations/apache-tomcat-7.0.29/logs/host-manager.2013-02-19.log
lr-x------ 1 mhewedy mhewedy 64 Feb 19 01:15 11 -> /windows/Work/linuxInstallations/apache-tomcat-7.0.29/lib/annotations-api.jar
lr-x------ 1 mhewedy mhewedy 64 Feb 19 01:15 12 -> /windows/Work/linuxInstallations/apache-tomcat-7.0.29/lib/catalina-ant.jar
.....................................
Notice that the stdin reads from /dev/null, the stdout write to catalina.out file.

17 August 2011

Step-by-step running Objective-c on Ubuntu Linux for Windows users

SA,

In this post, I'll try to compile and run the code in this Objective-c Wikibook lesson

If you are using M$ Windows, go download VMWare Player from here and then download ubuntu Linux, I am using version 10.04.. you can get some recent version if you like..

There are variety of tutorials online to help you install ubuntu on vmware.. it is a very trivial task..


Once you have your ubuntu distribution up and running (either a VM or a standalone installation)... keep reading ...

Ubuntu linux (and almost all linux distro) come with Parts of GCC (GNU Compiler Collections) pre-installed.

Let's test the existence of a C compiler. Now type in the command line the following command:

cat <<EOF>hello.c
#include<stdio.h>
int main(void){printf("In the name of Allah\n");}
EOF

And Then:
gcc -o hello hello.c && ./hello


If you find the following output printed on the console window, then we are going in the right direction:
In the name of Allah



Now let's install the Objective-c compiler into the GCC (it is about 4MB):
Open synaptic (from command line `sudo synaptic` [will prompted for your password]

Now search for "objc" in synaptic.. and then install the package "libobjc2".


Now we are ready...

Let's try to compile and run the example in the wikibooks link we have talked about before..

First create a directory in your home directory called "objc"
and then put the three files below in it

Here's the interface Point:

//Point.h
#import <objc/Object.h>

@interface Point : Object
{
@private
    double x;
    double y;
}

-(id) x: (double) x_value;
-(double) x;
-(id) y: (double) y_value;
-(double) y;
-(double) magnitude;

@end


(note, return to the wikibooks link if you need to understand the code)

And here's the implementation class:

//Point.m
#import "Point.h"
#import <math.h>

@implementation Point
    -(id) x: (double) x_value
    {
        x = x_value;
        return self;
    }

    -(double) x
    {
        return x;
    }

    -(id) y: (double) y_value
    {
        y = y_value;
        return self;
    }

    -(double) y
    {
        return y;
    }

    -(double) magnitude
    {
        return sqrt(x*x + y*y);
    }

@end

And now the Test file:


//Test.m
#import "Point.h"
#import <stdio.h>

int main(void)
{

    Point *p = [[Point alloc] init];
    [p x:10.0];
    [p y:20.0];
    printf("The Distance from Point %g to %g is %g\n", [p x], [p y], [p magnitude]);
    return 0;
}

Now let's compile the above program..
The easiest way to do so is to execute the following command from the same directory where these files exist (objc directory)

gcc -o Test *.m -lobjc -lm

Note, the `-lm` is required only because we use the math.h library.
now let's execute the program:
./Test 
The Distance from Point 10 to 20 is 22.3607


That's all.. hope that you find this post helpful..

12 February 2011

How to write a static library in Linux

I am going to illustrate how to write a static library in C for Linux.

requirements: a Linux distribution with GCC installed.

1- First, we need to write the header file of our library:

// complex.h
#ifndef _COMPLEX_H
#define _COMPLEX_H

typedef struct
{
    double real;
    double imaginary;
    
}complex_t;

void add(complex_t *const dest, const complex_t *const src);
static int assert_ptr_not_null(void *);

#endif

2- second, let's write the implementation for this libary:
//complex.c
#include <stdio.h>
#include "complex.h"

void add(complex_t *const dest, const complex_t *const src)
{
    
    if ( !assert_ptr_not_null((void*)dest) || !assert_ptr_not_null((void*)src) )
    {
        fprintf(stderr, "NULL Pointers passed");
        return;
    }
    
    
    dest->real = dest->real + src->real;
    dest->imaginary = dest->imaginary + src->imaginary;
}

static int assert_ptr_not_null(void *ptr)
{
    if (ptr == NULL) return 0;
    return 1;
}

3- let's compile the library (but not link it), use the following command to compile the library:

>cc -c complex.c

-c tell the compiler not to do the linking phase
this command will output a files named "complex.o", and it is the object file for our library

4- static libraries in C are archives that contains object files, so let's archive our object file.
use the following command :

>ar libcomplex.a complex.o
ar: is a regular archiving program found in Linux.
libcomplex.a: is the name of our library, it should start with "lib" and ends by ".a" and in between, you can name it as you like.
complex.o: is our object file generated from compiling complex.c in step 3

notice the generation of the library file libcomplex.a

5- we are done!, so let's examine the generated files before using the library.

First, we can use the command "nm" to see the symbols in our object file, use this command:
>nm complex.o
the output will be like:
00000000 T add
00000075 t assert_ptr_not_null
         U fwrite
         U stderr

Notice the existence of our functions (assert_ptr_not_null, add)

let's examine the library too:
>nm libcomplex.a 

complex.o:
00000000 T add
00000075 t assert_ptr_not_null
         U fwrite
         U stderr


6- now, lets use the libary, here's a test program that uses the library:

//program.c
#include <stdio.h>
#include <stdlib.h>

#include "complex.h"

int
main()
{
    
    complex_t *c1 = (complex_t*) malloc(sizeof (complex_t));
    complex_t *c2 = (complex_t*) malloc(sizeof (complex_t));
    
    c1->real = 10;
    c1->imaginary = 10;
    
    add(c1, c2);
    
    
    printf("%f\n", c1->real);
    printf("%f\n", c1->imaginary);
    
    printf("%f\n", c2->real);
    printf("%f\n", c2->imaginary);
    
    free(c1);
    free(c2);
    
    return 0;
}

first, we need to compile our program:
>cc -c program.c

then, it's time for linking the generated object file:
> cc -o program program.o -L. -lcomplex
-lcomplex: composed of "-l" + "complex" which is our library name (without both "lib" and ".a").
-L. : this instruct the linker (ld) to include the current directory among the paths it searches for locating object files/libraries. (so it can look in our libcomplex.a library)

this command will generate the binary file for us, it will be named "program", try executing it:

>./program

also, we can list symbols in this binary using th "nm" tool too.

thats all.

References:
Beginning Linux Programming, third edition, Wiley Publishing, Inc.

12 October 2010

Shell: a script file to search a directory of Jars about which jar cointains which file?

Hi folks,

Today I am coming with some shell script that is useful if you want to need to know from a group of Jars in certain directory which one of them contains a certain file (Java class)

#! /bin/sh

path=$1
segment=$2

if [ -z "$path" ] || [ -z "$segment" ]
then
echo "Usage: $0 <path> <segment>"
exit
fi

for jar in $path/*.jar ; do echo " *** $jar *** " ; jar tf $jar| grep --color=always $segment; done;

07 August 2010

About my Linux experience (non-technical)

Al salamo Alykom,

I have a lot of time posting some boring technical C oriented posts, so let me talk to you today about my Linux experience.

I adore Gnome too much (and hate KDE too much too :) )
I uses some themes in Gnome and hate the other themes.
About themes I like, first It is the legacy bluecurve theme of RedHat, I love this too much.
Also I love to mix bluecurve with Industrial theme, It is also cool.
Also I like to MACify my Gnome desktop, and may be use Ubunut's theme (ClearLooks).

Thats all about what desktops and themes I like.

02 August 2010

Installing and running GTK applications on Linux (Ubuntu 10.04)

Al salamo Alykom,
Hi folks, How are you...

Today I'll talk about installing GTK and building simple GUI app using it.

to install GTK+2.0, from the command line write:
sudo aptitude install gnome-core-devel build-essential

That's all.

Now, Let's write a simple program using gtk+:
#include <gtk/gtk.h>

int main( int argc, char *argv[] )
{
GtkWidget *window;

gtk_init (&argc, &argv);

window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_show (window);

gtk_main ();

return 0;
}

to compile, use the following command:
cc hello_gtk.c `pkg-config --cflags gtk+-2.0 --libs gtk+-2.0`

And here's the run result: