[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.

Firefox: sync add-ons on your machines

October 13, 2016 Leave a comment

I knew that Firefox could do synchronization with multiple machines but I never tried it. It changed today. I got fed up with the manual sync so I looked after it and found this nice description of the process: https://support.mozilla.org/en-US/kb/sync-your-add-ons-another-copy-firefox . For this you need a free Firefox account.

Categories: firefox Tags: ,

A nice JUnit tutorial

October 10, 2016 Leave a comment

I started to use Java again (I haven’t touched it for 5 years…) and I found a very nice JUnit tutorial. Here it is: http://www.vogella.com/tutorials/JUnit/article.html .

Links

  • MoreUnit, install this plug-in if you use JUnit
  • EclEmma, a free Java code coverage tool for Eclipse
Categories: java Tags: , , ,