Archive

Author Archive

cleaning a laser mouse

January 12, 2017 Leave a comment

Problem
I have a laser mouse that worked very well. However, about a week ago the cursor started to move erratically. It was not moving smoothly.

Solution
The optical eye is dirty and needs some cleaning. Put a little alcohol (I used pálinka) on the tip of a Q-tip, and clean the optical eye gently. It solved the issue for me.

Here is a video of the cleaning process. The relevant part starts at 2:25.

[manjaro] install new fonts

January 2, 2017 Leave a comment

Problem
Under Manjaro I wanted to install new fonts. I needed a font pack; I didn’t want to bother with individual fonts.

Solution
At https://wiki.archlinux.org/index.php/fonts#TrueType I found some packages:

  • ttf-ms-fonts
  • ttf-google-fonts-git
  • ttf-bitstream-vera
  • ttf-vista-fonts
  • ttf-hack

The Google font kit contains hundreds of fonts.

Gimp
If you type a text in Gimp and you want to see the text with different fonts, i.e. you want to browse the fonts, here is how to do it.

Move the mouse above the font selector button (between “Font:” and “Sans” on the screenshot) and use the mouse wheel. That’s the trick.

Categories: manjaro Tags: ,

[php] turn off deprecated errors

December 6, 2016 Leave a comment

Problem
I have a PHP application running on a webserver and the system administrator sent me an email one day that the Apache log is full of PHP deprecated warning messages and it is caused by my page.

The warning message was the following:

PHP Deprecated:  preg_replace(): The /e modifier 
is deprecated, use preg_replace_callback instead 

Solution
Investigating the code, I had “preg_replace()” all over the source. No way that I would correct them manually everywhere. I chose a quick and dirty solution and added the following line to the top of the entry PHP file:

error_reporting(0); // Turn off warning, deprecated, 
                    // notice everything except error

Done, no more barking. This tip is from here.

When the application stops running and terminates with an error, I’ll update the application.

Categories: php

convert mp4 to webm and ogv

November 5, 2016 Leave a comment

Problem
I wanted to share an .mp4 file on my webserver but Firefox didn’t play it. It turned out Firefox prefers the .webm and .ogv formats, while Chrome can play .mp4.

Solution

Convert mp4 then:

.mp4 to .webm

ffmpeg -i input.mp4 -vcodec libvpx -acodec libvorbis -b:v 600k -cpu-used 4 -threads 8 output.webm

To change the quality, play with the “600k” value (bitrate).

.mp4 to .ogv

ffmpeg -i final.mp4 -vcodec libtheora -acodec libvorbis -b:v 600k -cpu-used 4 -threads 8 final.ogv

Here the difference is the codec (libtheora instead of libvpx).

Maybe I missed something, but the .webm file seemed to me to have better quality than .ogv. So I think it’s enough to support two formats only: .mp4 for Chrome and .webm for Firefox. By the way, in my test the input file (.mp4) had the best quality and smallest filesize, but again, I may miss something.

And here is an HTML5 code that can play your video:

<video controls preload="metadata" width="1024" height="768" poster="images/front.jpg">
    <source src="video.mp4" type="video/mp4">
    <source src="video.webm" type="video/webm">
    <p>Please use a modern browser to view this video.</p>
</video>
Categories: firefox Tags: , , , , , ,

[manjaro] no sound

November 3, 2016 Leave a comment

Problem
After a reboot sound stopped working.

Solution
After a few hours of trying everything, the following solution worked for me:

  1. delete the folder ~/.config/pulse
  2. pulseaudio -k
  3. pulseaudio --start
Categories: manjaro Tags: ,

Detailed Twitter info in JSON: an undocumented feature

October 24, 2016 Leave a comment

Problem
Using a script, I wanted to figure out the number of my followers on Twitter. Here is my (mostly abandoned) Twitter page: https://twitter.com/szathmar . I didn’t want to use any API since I didn’t want to register for an API key so I went on the easy way: let’s scrape the necessary data out :) Digging in the HTML code I found the number of followers, but I also found a hidden treasure!

Solution
And the hidden treasure is a long json string that contains all kinds of information about a twitter user:

hidden_json2

Here on the screenshot you can see just an extract, the json string is much longer. Fine, let’s get it!

#!/usr/bin/env python3
# coding: utf-8

import json
import readline
import sys
from pprint import pprint

import requests
from bs4 import BeautifulSoup

def main():
    url = input("Full twitter URL: ")
    html = requests.get(url).text
    soup = BeautifulSoup(html, "lxml")

    tag = soup.find('input', {'class': 'json-data'})
    j = tag['value']
    d = json.loads(j)
    json_out = json.dumps(d, indent=4)
    print(json_out)

    # followers = d['profile_user']['followers_count']
    # print(followers)

##############################################################################

if __name__ == "__main__":
    main()

If you want the number of followers for instance, then uncomment the last two lines.

Thank you Twitter! It’s really nice of you to provide all these data in JSON!

Sample
The JSON that I could extract from my page is 743 lines long! Here is an extract of it:

...
"profile_image_url": "http://pbs.twimg.com/profile_images/459783802395430912/vcMT0CGX_normal.png",
"business_profile_state": "none",
"url": null,
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme6/bg.gif",
"screen_name": "szathmar",
"is_translator": false,
"friends_count": 123,
"followers_count": 70,
"profile_text_color": "333333",
"profile_link_color": "FF3300",
"translator_type": "none",
"profile_background_color": "709397",
...
Categories: python Tags: , , ,

[wordpress] using the old-style editor

October 16, 2016 Leave a comment

Problem
Wordpress.com introduced a while ago a new-style editor for writing posts. However, I really hate it, it’s unusable. How to get back to the old-style editor?

Solution
Transforming the URL you can get back to the old-style editor. For instance:

new style: https://wordpress.com/post/ubuntuincident.wordpress.com/5865
old style: https://ubuntuincident.wordpress.com/wp-admin/post.php?post=5865&action=edit

Let’s automate the task with Python:

#!/usr/bin/env python3
# coding: utf-8

import readline
import webbrowser

def main():
    url = input("New style URL: ")
    parts = url.split("/")
    new = "{0}//{1}/wp-admin/post.php?post={2}&action=edit".format(
        parts[0], parts[4], parts[-1]
    )
    print("New style:", new)
    webbrowser.open_new_tab(new)

##############################################################################

if __name__ == "__main__":
    main()

Screenshots

New-style shit.

New-style shit.

Old-style goodie.

Old-style goodie.