Posts

  • Progress meter for Python loops

    Awesome library I use all the time.

    tqdm Python loops

  • Compiling tmux 2.0 on Ubuntu 14.04

    Ubuntu repositories have outdated tmux version, so I like to compile my own.

    sudo apt-get install -y exuberant-ctags cmake libevent-dev libncurses5-dev
    wget https://github.com/tmux/tmux/releases/download/2.0/tmux-2.0.tar.gz
    ./configure && make
    sudo make install
  • Converting SOCKS5 to HTTP for Python Requests

    Sometimes we need to access services, that have limited access and can be accessed only from our production servers.

    The best solution is to use SSH tunnel, but SSH tunnel can’t create HTTP proxy, while requests supports only SOCKS5 proxy.

    Our solution called DeleGate, extremely powerful proxy server.

    Lets compile DeleGate

    wget ftp://anonymous@ftp.delegate.org/pub/DeleGate/delegate9.9.13.tar.gz
    tar xvzf delegate9.9.13.tar.gz
    cd delegate9.9.13
    make

    Lets launch our SSH tunnel and then launch delegate to create local HTTP proxy:

    ssh -D 127.0.0.1:9556 -p 2022 user@production-server
    src/delegated -P9555 SERVER=http SOCKS=localhost:9556

    Now we can user our HTTP proxy in Python:

    response = requests.post(request.url,
                             data=request.json,
                             proxies={'http': 'http://127.0.0.1:9555'},
                             headers={'Content-Type': 'application/json'})
  • Running Android Emulator (Genymotion) on remote server

    Android using VNC

    I have a need to run Android applications in remote environment. This is a little more complex than I thought.

    I’m running Linux Mint 17.1 XFCE (based on Ubuntu 14.04). This distribution uses MDM display manager.

    We are going to use Genymotion Android emulator, the best option for Linux systems.

    So, first of all lets install latest version of VirtualBox.

    1. VirtualBox

    Genymotion uses VirtualBox as its virtualization software, so lets install that first. I would recommend you to install VirtualBox 4.3, not the one in default repositories.

    First install the dependency package to avoid error.

    sudo apt-get install dkms

    After that we need to install Oracle public key.

    wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -

    For Ubuntu 15.04

    sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian vivid contrib" >> /etc/apt/sources.list.d/virtualbox.list'

    For Ubuntu 14.10

    sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian utopic contrib" >> /etc/apt/sources.list.d/virtualbox.list'

    For Ubuntu 14.04 (Linux Mint 17.1, Linux Mint 17)

    sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian trusty contrib" >> /etc/apt/sources.list.d/virtualbox.list'

    For Ubuntu 13.10 (Linux Mint 16)

    sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian saucy contrib" >> /etc/apt/sources.list.d/virtualbox.list'

    For Ubuntu 13.04 (Linux Mint 15)

    sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian raring contrib" >> /etc/apt/sources.list.d/virtualbox.list'

    For Ubuntu 12.10 (Linux Mint 14)

    sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian quantal contrib" >> /etc/apt/sources.list.d/virtualbox.list'

    For Ubuntu 12.04 (Linux Mint 13)

    sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian precise contrib" >> /etc/apt/sources.list.d/virtualbox.list'

    For Ubuntu 11.10 (Linux Mint 12)

    sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian oneiric contrib" >> /etc/apt/sources.list.d/virtualbox.list'

    For Ubuntu 11.04 (Linux Mint 11)

    sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian natty contrib" >> /etc/apt/sources.list.d/virtualbox.list'

    For Debian 7.0 ("Wheezy")

    sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian wheezy contrib" >> /etc/apt/sources.list.d/virtualbox.list'

    For Debian 6.0 ("Squeeze")

    sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian squeeze contrib non-free" >> /etc/apt/sources.list.d/virtualbox.list'

    Okay, we are ready to install VirtualBox 4.3 now!

    sudo apt-get update
    sudo apt-get install virtualbox-4.3

    2. Genymotion

    Go to Genymotion and install appropriate version for your system on your server.

    3. VirtualGL

    Genymotion requires hardware acceleration, so we cannot simply use ssh forwarding. Lets download and install VirtualGL.

    sudo dpkg -i virtualgl_2.4.1_amd64.deb

    Run server config script

    sudo /opt/VirtualGL/bin/vglserver_config

    I have my server in safe local environment, so I don’t need restricting access to vgl capabilities.

    "Restrict 3D X server access to vglusers group?"  No.
    "Restrict framebuffer device access to vglusers group?"  No.
    "Disable XTEST extension?"  Yes.

    If you will get these errors

    ERROR: ld.so: object 'libdlfaker.so' from LD_PRELOAD cannot be preloaded: ignored.
    ERROR: ld.so: object 'librrfaker.so' from LD_PRELOAD cannot be preloaded: ignored.

    you can try this:

    chmod u+s /usr/lib/librrfaker.so
    chmod u+s /usr/lib/libdlfaker.so

    4. TurboVNC

    Download and install TurboVNC.

    sudo dpkg -i turbovnc_1.2.3_amd64.deb

    5. x11vnc

    sudo apt-get install x11vnc

    Create a password for your user:

    x11vnc -storepasswd

    Lets run x11vnc. I’m using Linux Mint XFCE 17.1, so my display manager is mdm. You can change -auth parameter according to your display manager:

    If NO ONE is logged into an X session yet, but there is a greeter login
    program like "gdm", "kdm", "xdm", or "dtlogin" running, you will need
    to find and use the raw display manager MIT-MAGIC-COOKIE file.
    Some examples for various display managers:
    
     gdm:     -auth /var/gdm/:0.Xauth
              -auth /var/lib/gdm/:0.Xauth
     kdm:     -auth /var/lib/kdm/A:0-crWk72
              -auth /var/run/xauth/A:0-crWk72
     xdm:     -auth /var/lib/xdm/authdir/authfiles/A:0-XQvaJk
     dtlogin: -auth /var/dt/A:0-UgaaXa

    x11vnc talks to the local X11 server and copies the framebuffer from the server to the client via vnc. Since the local X11 server renders everything with hardware acceleration, I get hardware accelerated OpenGL over VNC, even with all the cool desktop effects. This is how I start x11vnc:

    sudo x11vnc -dontdisconnect -notruecolor -noxfixes -shared -forever -rfbport 5900 -bg -o /home/brucewayne/.vnc/x11vnc.log -rfbauth /home/brucewayne/.vnc/passwd -auth /var/lib/mdm/:0.Xauth

    6. Running Android

    Now, lets log in into our server

    /opt/TurboVNC/bin/vncviewer -via 192.168.1.68 localhost:5900

    where 192.168.1.68 is our server IP. It will ask for your x11vnc password.

    Now, inside our VNC session you can do

    vglrun ./genymotion

    7. Installing Google Play Services

    If you want to install Google Play Services, go here https://gist.github.com/wbroek/9321145

  • Awesome JavaScript books

    Today I want to recomment amazing JavaScript books from Kyle Simpson, who initially raised money on KickStarter and now continues series of his amazing books. You can buy them, and you can read them online for free!

    1. Up & Going
    2. Scope & Closures
    3. this & Object Prototypes
    4. Types & Grammar
    5. Async & Performance
    6. ES6 & Beyond (in production)
  • ElasticSearch Tutorials

    Found two amazing video lectures about ElasticSearch

  • Stack, Heap, Virtual Memory, Linux Assembly

    Memory layout

    Also worth reading: Call Stack and “What is the purpose of the frame pointer?

  • How memory works?

    I’ve struggled for years to understand how computer memory and CPU works at low-level. I didn’t really used it, but I’ve always wanted to. I’ve tried to study ASM with no success, only to understand that I need to learn more about CPU and RAM. These videos I’ve found to be very useful.

    Also, if you can find material from Software Security from the University of Maryland - that would help you as well.

  • Hello, world!

    After years being a Web Developer (mostly PHP, some Python too) I’m gradually switching to lower level programming language C. In this blog I will log my learning process and will try to help other developers with same problems.

    I need to notice and I’m working with linux system only.

    So, I will log my adventure through low-level programming. Join me and lets have fun!

    BTW: currently, I’m on the task 05 of Eudyptula Challenge and it’s just awesome. I highly recommend it.

subscribe via RSS