Category: Uncategorised

  • Force firefox to use light theme for content widget, even when choosing dark GTK+ theme.

    The problem that had been haunting me for so long is firefox and dark theme. When choosing a dark GTK theme, firefox will use that same theme for widgets on website, especially website with forms. Now, most website will try to tweak the display of their form widget a bit, but not all website did a good job tweaking. They may default font color form black to dark grey but leave background unchange. Or they may change background color to light grey but still use default fonts.

    In both cases, we ended up with broken website when I enable dark theme (grey text on dark background)

    Un readable text when using dark gtk theme on some website

    The default grey font on light background that website prefer is completely incomprehensable.

    But chromium doesn’t seem to have this problem because chromium enforce its default theme for website’s widget, and completely disregard system theme. This is an imperfect solution but it fits in an imperfect world. So after much googling around I found a reddit thread

    https://www.reddit.com/r/firefox/comments/9s2so2/firefox_linux_gtk_dark_theme_issue_solved_in_v63/

    Turned out this was report as a bug 3 years ago and 2 years ago came a work-around: Go to about:config and add a new string preference name: widget.content.gtk-theme-override

    Then you can enter any light theme you want to be use as default theme for website content widget. You can even enter a wrong theme name, it will default to system theme (which is a light them on most gnome distro). Then voila:.

    Now with the work around
  • Launch gnome-terminal with a specific profile from within code::blocks

    I use code::blocks when teaching Programming introductory courses because it’s simple to install and get going. However, when running code from codeblocks it will default to launch xterm, which is not quite my taste. So I naturally go to:

    Settings -> Environment

    Then change the setting: “Terminal to launch console programs” to gnome-terminal. Most of the time I run code in codeblocks, I have to show the terminal on the school projector with horrendous contrast that make almost to read white text on dark background. Now the problem is I love dark background on my terminal and don’t want to change my gnome-terminal to  light background. Install another terminal just for use with codeblocks on projector could solve this but seem like a waste of resources.

    Fortunately Gnome-terminal support multiple profile with different display settings and there is an argument for you to choose profile when launching. So, I create a “project” profile within gnome-temrinal with enormous font, light background, etc, ideal for readability on projectors.

    Then in codeblock edit setting to launch gnome-terminal with this special profile:

    gnome-terminal -t $TITLE --profile=projector -x 


  • Film review: Tháng năm rực rỡ

    Cũng lâu rồi blog không có bài nào tiếng Việt, thôi giờ review film Việt thì viết tiếng Việt đỡ chứ chả lẽ viết tiếng Anh mãi trong khi mình biết mình viết dở. Nói chung là bị rủ rê đi xem film và cũng lâu rồi không đi ủng hột một film Việt nào. Xem trailer thì không ấn tượng lắm nhưng có dàn diễn viên nữ nổi như cồn thời mình còn nhỏ nên xách mông lên đi thử. Xác định trước trong lòng là không đặt hy vọng quá cao vì film Việt bây giờ makerting trái chiều nhiều quá, khen đó rồi có khi chê đó mà cái tính của mình thì cỡ như Wonder Woman mìn còn lôi ra được sạn nữa là.

    Nhìn một cách tổng thể thì film có tính giải trí cao, coi cũng hài. Nếu như không phải là film remake thì có lẽ cũng đáng được một lời khen. Nhưng với film remake mình thường có cái nhìn khắt khe hơn, đặc biệt là về cốt truyện và logic. Cốt truyện thì đã có film gốc nó lo rồi, giờ chỉ chuyển thể lại thì nên chăm chút hơn ở các chi tiết.

    Nhân vật chính hồi 15 tuổi nói giọng rặt Thái Bình, sau 25 năm tới 40 tuổi thì nói giọng Nam bộ ngọt ngào trầm ấm là hơi kỳ rồi. Ừ mà thôi film cũng có giải thích là “nhập gia tùy tục” đi nhưng nhập thế quái nào mà ở giai đoạn trước năm 2000 phẫu thuật thẩm mỹ chưa phát triển cô gái ấy lại tự mọc thêm ra được hai cái lúm đồng tiền vậy???

    Film đặt bối cảnh là nhóm bạn thân hồi lớp 11 phải tan rã vì chiến sự năm 1975, ờ thì thôi cũng tin là vì loạn lạc mà thất lạc tin nhau đi. Nhưng cách họ gặp lại nhau thì phải cho nó hợp lý tí. Nhân vật chính vô tình gặp lại cô “nhóm trưởng” năng động ngày xưa khi thấy cô ấy đi điều trị ung thư giai đoạn cuối trong bệnh viện. Quả là nhiệm màu.

    Sau đó cô nhân vật chính nhìn học sinh tan trường mà chợt nhớ lại thời học sinh và rồi cô phóng xuống xe đi bộ sau đó cô chui tọt vào phòng làm việc của cô giáo ngày xưa và hỏi “cô còn nhớ em không”. Mother of nhiệm màu, phóng đại một phát vào cái trường nào đó ở Sài Gòn cái vô ngay phòng của cô giáo ngày xưa dạy tuốt trên Đà Lạt, trong khi rõ ràng trước đó cô này không có tin tức gì của bạn cả chỉ tình cờ thấy bạn sắp chết trong bệnh viện.

    Sau đó khi gặp lại băng nhóm học đường ngày xưa của mình cô nhân vật chính rủ cả nhóm đi kiếm chuyện đánh dằn mặt bạn học của con vì cái tội “dám ăn hiếp con bà”. Cái thế giới gì ở đây vậy trời. Phụ huynh già đầu có cả người làm ăn giàu có rồi mà đi đánh nhau với học sinh cấp 3 là sao. Mấy bà đó có tiền mà, muốn đánh thì cứ thuê giang hồ vả méo mồm mấy con ranh đó ra chứ làm cái gì mà lố lăng coi không có được. Chuyển thể cho nó hợp lý một tí chứ trời. Thời mình còn đi học, đúng năm 2000 theo bối cảnh của film, học sinh một trường đàng hoàng có ăn hiếp nhau cũng phải biết sợ phụ huynh. Không có cái kiểu trả treo mất dạy như trong film. Còn loại học sinh mà dám bật cả phụ huynh của bạn thì chỉ có là trẻ bụi đời chứ không phải học sinh. Loại này mà đụng vào nó kêu băng của nó tới xiên lòi ruột chứ không có cà búng cà búng như trong film.

    Và cuối cùng là cái sai nặng nhất với mình, đó là sai bối cảnh lịch sử. Trong film có cảnh sinh viên biểu tình trên đường sau đó choảng nhau với cảnh sát dã chiến. Trang phục này nọ thì OK hết cả đấy nhưng nó không đúng lịch sử. Phong trào sinh viên phản chiến ở Miền Nam mạnh nhất là vào các giai đoạn từ 1967 – 1971 khi hầu hết lãnh đạo Tổng Hội sinh viên đều có liên hệ với chính phủ cách mạng lâm thời miền Nam Việt Nam. Sang giai đoạn 1972-1975, hầu hết lãnh đạo thân chính phủ cách mạng chủ chốt như Huỳnh Tấn Mẫm đều bị bắt cầm tù. Và đặc biệt trong giai đoạn đầu năm 1975 khi chính quyền miền Nam mất tỉnh Phước Long thì không khí chiến sự rất căng thẳng. Việc học sinh sinh viên còn có khả năng tổ chức biểu tình trong cái không khí đó không tưởng, mà có biểu tình được thì cũng ăn đạn chứ không có ăn dùi cui như trong film.

    Tiếp đó là bối cảnh trong film nhóm bạn thân đang chuẩn bị tiết mục văn nghệ cuối năm thì chia tay tan rã vì chiến sự (tan rã vì chiến sự thì dễ tin chứ tan rã vì bị đuổi học như trong film thì quá sức tào lao. Đặc biệt . Trong đó có cảnh chiếc xe của binh lính Sài Gòn đang rút chạy. Văn nghệ như vậy thì phải vào đợt cuối tháng 4. TrongkKhi đó theo lịch sử thì chiến dịch Tây Nguyên đã bắt đầu từ hồi đầu tháng 3 với trận mở màn chớp nhoáng ở Buôn Mê Thuột. Sau nhiều cuộc phản kích tái chiếm không thành thì từ giữa tháng 3 quan đội Sài Gòn đã rút khỏi Tây Nguyên, Đà Lạt (Lâm Đồng) rơi vào thế cô lập. Quân đội Nhân dân Việt Nam chỉ còn việc nhẹ nhàng giải phóng từ phần của tỉnh Lâm Đồng từ ngày 17 tháng 3 và tới ngày 3 tháng 4 thì giải phóng thành phố Đà Lạt. Trong bối cảnh đó mà còn có cái trường nào tổ chức văn nghệ với bầu chọn hoa khôi thì đúng là điên rồ.

    Đó là vài cái sai logic lớn, sai nhỏ thì nhiều, chủ yếu do bê y chang nội dung film Hàn qua mà không thèm sửa nhưng mà nhiếu quá nhớ không hết nên thôi khỏi ghi vậy. Về phần diễn viên tất cả đều đã rất cố gắng nhưng không hiểu tuyển không nổi diễn viên hay sao mà cùng một nhân vật ở thời 15 tuổi với thời 45 tuổi không có bất cứ cái ăn nhập nào với nhau. Nét diễn của mỗi người cũng khác nhau luôn. Lúc coi film cứ phải cố gắng suy nghĩ lắm mới kết nối hai diễn viên vô một nhân vật, làm mệt não người xem một cách không cần thiết.

    Cuối cùng điểm cộng chính cho film là ở cảnh quay. Không phải là những đại cảnh quá vĩ đại và hoành tráng hay những khung cảnh đầy tính hình tượng và nghệ thuật, nhưng phần bối cảnh của film được làm khá kỹ. Cảnh quay ưa mắt, các chi tiết chăm chút cho phù hợp với từng giai đoạn của film. Hầu hết film Việt mình thấy trong giai đoạn gần đây đều làm khâu này ổn, và film này cũng không ngoại lệ. Một điểm cộng bù đắp lại cho mấy cái sai bên trên vậy.

     

  • Building a home media streaming server. Part 2: The streaming server

    Building a home media streaming server. Part 2: The streaming server

    Now that I got my TV hook up to the laptop and the PC working as the media server serving those FullHD x264 film over the air. I can simply install  on it and got top notch home media experience,  just look at this beautiful picture, it sure speak more than thousands word:

    However, the problem with those massive HEVC(x265)10bit high bitrate film remain. My laptop simply can’t open those files. I will have to transcode those file and stream it to the laptop. In short, my work station will have to be Youtube, or something like this:

    The survey

    I tried to build a streaming server but to no avail. First is making a trip to the guide: https://wiki.archlinux.org/index.php/Streaming_media

    That link provide quite a few streaming software available on  arch that can stream over DLNA/UPnP protocol. Now as far as I’m concerned, DLNA is meant to stream to media player device that doesn’t have full capacitiy of a laptop computer and thus the server has to transcode the file to a more easier to read format and that’s exactly my use case. Looking on the list of streamer sever software, some catch the eye:

    1. ReadyMedia, formerly known as minidlna, this is a simple and no fussy solution, just like it’s name suggest. You edit the config file, start the server and the media appear on your client, just that.
    2. Gerbera, formerly known as MediaTomb. I did try this server to a horrible experience. It was so buggy and the config file was so so complex that I find no way to make it work and abandon the streaming stuff all together. But with it’s code fork  and make into gerbera, maybe thing will be a bit better
    3. Emby. This software is new and it has a beautiful website for an opensource app. I don’t like the fact that it was coded in C# though but if it work good I can make a pass for that.
    4. Plex. This is a closed-source solution so I was deterred to try it last time. It requires you to registered a free account to get token to access your own media collection. It has an option to make stream your data over the internet, but, for a closed-source solution that sound more scary than cool. But if you don’t concerned about closed-source, Plex has a really good reputation of working find and looking beautiful.

    So, how can a tech savvier choose his favourite streaming server among those? He tried them all on 🙂

    ReadyMedia

    This software is a resurrection of MiniDLNA, and as its name suggests, this software is lightweight and simple to use. Archwiki already got a pretty decent article on this piece: https://wiki.archlinux.org/index.php/ReadyMedia. However, since I also need transcoding feature, I have to install patched version from bitbucket. Arch’s AUR ease up the installation a bit https://aur.archlinux.org/packages/readymedia-transcode-git/ but the old source code won’t compile with the shinny and new ImageMagick version 7.

    A little hack is required, and I left a comment in arch’s aur page (linked above). After the minidlna server is up and running, any media player that support dlna protocol can see and open file from my homePC. Kodi con do it but I setting kodi is story for part 3 of this series, one can test if dlna server is up by using the quick and easy vlc :

    Just open VLC, then go to View -> Playlist (Ctrl + L) and select Universial Plug 'n' Play under Local Network section.

    Your sever will be listed on the right side and you can browse it by  folders of just get a list of every media file that the server understand.

    # list of video containers that needs to be transcoded
    # possible values can be obtained by running "ffmpeg -formats"
    # The format in which the settings should be written is the same
    # as the format used for the "transcode_audio_codecs".
    transcode_video_containers=
    # list of video codecs that needs to be transcoded
    # possible values can be obtained by running "ffmpeg -codecs"
    # The format in which the settings should be written is the same
    # as the format used for the "transcode_audio_codecs".
    transcode_video_codecs=vp8/theora/flv/flv1/svq3/hevc
    # full path to the transcoder that is used for video transcoding
    # for details, see comments on transcode_audio_transcoder
    transcode_video_transcoder=/opt/transcode_video-hq
    

     

    You can either specify the containers (the extensions) you want to transcode or the codecs that will be transcode, or both. Since my laptop only struggle with x265 (HEVC) file, I simply add hevc at the end of the line transcode_video_codecs.

    transcode_video_transcoder specify the wrapper script to call a program at your choosing that will be used to actually perform the transcoding. The example script that come with ReadyMedia is easy enough to grasp:

    #!/bin/sh
    
    SOURCE=$1
    STARTPOSITION=$2
    DURATION=$3
    
    ffmpeg -ss $STARTPOSITION -t $DURATION -i "$SOURCE" -loglevel quiet -threads auto -async 2 -vcodec mpeg4 -f mpegts pipe:1 -scodec copy 
    

     

    That script take 3 arguments then call ffmpeg to perform the transcoding. The output will be put into standard pipe and then stream to the client.

    However, I soon run into a big problem: I CANNOT SEEK

    Yeah, no matter how much I tweak ffmpeg argument and ReadyMedia setting, seeking doesn’t seem to work. The seek button on client won’t work, some client even won’t report movie run time. Now that is impossible to use, I can bare with no subtitle or some film, but the most important of watching film at home is that you can forward and backward to the scene you love the most, with no seeking, the experience is nothing more than and old TV.

    I did try  but even though it works much better and bug free then the old MediaTomb, I couldn’t find any improvement on transcoding and seeking. In fact, the old transcoding guide for MediaTomb flat out says that seeking is IMPOSSIBLE.

     

    (sidenote: old like to mediatomb website seem dead but the old guide is available in google search’s cache). The only improvement over ReadyMedia that Gerbera can bring to the table is a web interface to do the configuration. That’s it. No improvement in transcoding than I can found. So my search for the solution continue into the realm of proprietary software.

    Plex and Embry

    The thing I found out when tried on  is that their reputations are well deserved. Installation is easy, configuration is easy and everything just work. After install the server package onto my HomePC, I can access the MY Plex homepage from the local network via the default port 32400. And Man, it was beautiful. Just hover your mouse on the LIBRARY section then click the Plus (+) icon, one will be greeted with the dialog to add a new library.

    First, we choose Library type, then browse to  a folder on the disk where the media file is stored. Now just like Kodi, if you choose either Films or TV Programmes, Plex will automatically pull all metadata for those movie and TV shows from imdb, and it will show ONLY the file it recognize as Films or TV Programmes respectively. It’s mean some clip that one really mean to hide won’t show up on the plex library, hooray!

    About the transcoding, well, I must say it’s not quite as easy as the rest. Plex support transcoding out of the box but the option to transcoding 4K resolution only “automatically” appear if I really watching the video on a 4K window

    Therefore, I cannot test it out on my laptop alone without plugging it into the TV, and that’s inconvenience. And even though the transcoding work, I can enjoy the movie without those massive frame dropping, it put a huge strain on both client and server. Even without the need to decoding, putting all the pixel at that massive bitrate on the screen is back breaking work for my laptop

     

    With CPU jumping between 70% to 90% utilizing across all 2 core, 4 threads, all I can do is enjoy the movie because the laptop hardly response to anything else.

    On the server side thing is also pushed to the very edge. My homePC is not equipped with streaming oriented hardware and just decode those HEVC codec alone already put 60% CPU usage on it. Having to re-encode those pixel and transport it over the network and the CPU usage jump to 80-90%.

    And the strain on network is also enormous. I’m not a professional in setting up high speed network so my WiFi can only push out about 28Mbps, barely enough for some 4K movie, some other will suffer from stuttering play back. That’s a little bit disappointing at first, I didn’t think a home WIFi network with me as the only primary user would be insufficient for 4K playback. But since a HTPC with dedicate wired Ethernet connection was in plan, I guess I have to bare with the stuttering for now.

    Emby

    Emby is the closest thing to Plex. Unlike Plex, it employs a Free/Open source version along side a “Premiere” version. The Free/Open source part provide enough features and usability for me. It automatically recognize files in your chosen folder and pull all metadata from the internet. Emby provide native app for a barrage of Mobile and TV devices but I haven’t the need for any of them yet.

    For PC platform emby provide just the web application and it’s seem good enough, though the interface is not as glamorous as Plex’s.

    The playback however is not as smooth. Due to the lack of a PC client app, Emby have to transcode almost every single mkv file or mine to suitable codec for web playaback. And the transcoding process is just Monstrosity. The CPU usage on my HomePC quickly jump to 100% and keep staying there, the whole system become lagging and even then I suffer stuttering playback. It seem like my system was just not strong enough for Emby and by the time I have money to upgrade it I won’t need emby anymore so that was the end of my Emby experience.

    The conclusion

    So, at the moment, whenever I want to enjoy a 4K movie, I fire up plexmediaserver on my HomePC and Plex Client on my laptop then hookup the laptop to TV and voila. It’s not perfect but at least I decent.

    The next part of this series will deal with how I equip my laptop to double as a poor-man-HTPC, include both software and hardware modification needed.

  • Building a home media streaming server. Part 1: The media server

    Building a home media streaming server. Part 1: The media server

    This will be a multi part blogging of my journy to build a Home Theatre PC (HTPC), becasue so many things was learned to put all in a single post.

    The context

    The TV

    After a very long long long time of ear whispering and diner table talking, I finally persuade mom to get rid of the old junk CRT TV to make space for my new 4K TV.  Even though I had long saved up enough for that TV, I simply couldn’t find a place to put it because the house is cramping and Mom was reluctant to part way with the good old  and sentimentally valuable furniture.

    So I quickly dash to the electronic store and bring back the Panasonic TH-43EX605V 

    The TV look good but the room in the advertisement look even better

    It was the cheapest, none Chinese brand, 4K TV with HDR support in the store, nothing fancy but to the one who never use big screen before, it was HUGE!!!

    The TV in action

    The plan

    So the challenge is finding content to be watched on this TV. My cable company provide TV services but they are capped at FullHD 1080p. The majority of my 4K content come from private torrent tracker where  I can leech a bunch of movies or TV-series RIP in 4K x265 format:

    some movie in my favorite tracker

    Even though my TV promote itself as “smart”-TV, I pretty much don’t care about those features since it has a slow as hell processor and completely helpless against file with x265 codec. My long term goal is to build a HTPC and connect it to the TV  since I has got tons of experience using PC anyway, it would be a less step learning curve than having to deal with the TV’s peky apps. The plan is to upgrade my current PC then scavenge old parts to build the HTPC. But with the meltdown and spectre haunting all CPU giants, it’s best to delay upgrading the PC until new hardware with no vulnerable come out.

    And so, I decided to use my laptop to double as the HTPC and my current PC will double as the Home media server (HMS). And this blog post will document what change need to be made for those to computer to serve as their double role.

    The server

    The easy start

    First of all, since I’m pretty much the sole user of this HTPC-HMS setup, there are a lots of use-case that I won’t have to wory about. First of, I don’t have to get all of my movie archive online at all time. There’s no need to setup NAS or huge storage server, I can keep the film I already watched archive and stashed away in backup hard disk, only hot-swap them in the server when I’m really in the mood. So it’s pretty much “just install openssh” and the server is done.

    On the server, install openssh and start it

    # pacman -S openssh 
    # systemctl start sshd

    Then on the client (my laptop) just open Nautilus and connect:

    In just type the ip address, preceded by sftp:// and then enter your server’s account username and password then you’re all set. In fact I love file sharing on linux so much more than it is on windows. No twiddling with “Network and sharing settings” and stuff. Then same protocol that’s used to control computer can be used for file sharing with traffic encryption and all. After you connect, it’s only the matter of drag and drop the mkv file into your favourite media player on the laptop.

    However, I soon ran into trouble when I download a movie that was encode with so high bitrate my laptop can’t open :O

    The Problem.

    My laptop is the first-gen Dell XPS13 (9343 model) with only a Broadwell CPU (i5-5200U), and only the next gen with Skylake CPU would support decoding HEVC (x265) 10bit profile. 

    The 3:10 to Yuma with it’s 14204 kbps bitrate would drive my laptop CPU to 99% usage and the fan was screeching like crazy.

    So, Dunkirk with its  24258 kbps is simply too much for my laptop CPU to handle. Frame was dropping left and right and audio was going a full second and a half before video can catch up. Totally unwatchable.

    Now my PC doesn’t fair much better, neither the i5-3550 nor the Geforce GTX750 have native x265 decoding capability but at least my PC CPU can open that file with 60% CPU usage.  So now I’m left with a few choice while saving up for new hardware:

    1. Buy a 15 meters HDMI cable to connect the TV to PC.  This would ensure best performance but that’s almost the maximum length on HDMI 1.2 cable and it won’t come cheap. Moreover, zigzagging 15m of hard cable around the house is no fun job! Where’s the “coolness” in this method? It quickly passed up.
    2. Decode the file on my PC and stream the decoded video over wifi to the laptop. Now that solution would stretch my tech exprience to it’s limit and one cannot expect a more cool solution. I got a chance to face-off with my old enemy “the task of setting up media streaming server”.

    And it’s time to wrap up part 1. Part 2 will document my expermiment with various streaming solution.

     

  • [Vestacp] Increase database username length limit

    For so long mysql has a harcoded 16 characters length limit on username. And vestacp enforce this limitation, every database username have to be less than 17 characters long.

    The problem is mysql has increase this length limit to 32 charcaters and mariadb even remove this limit completely but vestacp hadn’t lift their limit yet for the sake of compatibility. So, until this issue closed: https://github.com/serghey-rodin/vesta/issues/860, if you have mysql 5.7+ and want to make really long username, you have to change vesatacp’s code.

    Open file /usr/local/vesta/func/main.sh

    Find those line

     if [ 17 -le ${#1} ]; then
     check_result $E_INVALID "mysql username can be up to 16 characters long"
     fi

    Now change the number 17 to 33 and you essentially double the username length limit.

  • Glass castle film review.

    I seldom write film review, even though I pirated and watched lots of film, mostly because I am lazy, but more often than not I only talk about film than I can reflect upon my own life, like “Rain man” for example.

    Recently I stumble upon Glass castle (http://www.imdb.com/title/tt2378507/)

    The rating was mediocre but I love it because I can relate to the protagonist feeling about her alcoholic father. If an alcoholic can manage to get a family, you can be sure that he/she is very charming when given enough liquor to function. Really, an unattractive alcoholic can only end up in a grave or a prison cell alone, no one would come near them. A charming and family alcoholic man on the other hand, is a roller coaster ride of emotion. He can give you hope that never materialize. He can give you joy that immediately follow by sadness. He can make you feel safe, only to terrifies you himself moment later. And he is never never reliable.

    The film was based on a memoir of a famous writer, so it’s good source material. And the acting was superb. Man! If it was up to me I would award an Oscar for both leading actor and actress. Even though her screen time was limited, Brie Larson did a good job in the film. She has already kick Jennifer Lawrence out of my heart, and only rival with Emma Watson. I will be sure to follow her films in the future. The lead actor has been twice nominated for Oscar but never won. He did a good job in this film, I hope it can be his time to shine.

    And finally I’m always bias toward film that I can relate to my own life but this film was really a good watch.

  • Using Code Igniter pagination class with bootstrap 4.0-beta2

    Code igniter have a helper class to generate pagination for a page. This class is fairly primitve but highly customizable, and since I’m lazy mood I gooogle around finding some ways to customize it to work with bootstrap 4.0-beta2. So at first I came across this snippet: https://github.com/zulacom/ci-paging-bootstrap-4/blob/master/pagination.php but this snippet do well in mimicking the look but was annoying to use.
    The problem is: Codeiginiter pagination class allow you to wrap the link ( <a> tag) between some others custom tags. Bootstrap however require you add class .page-link in those tag directly. The snippet above solve this by wrapping tag around a span.page-link tag, produce something like this:


    This look good but you cannot click on the <span> square, you have to click on the number itself to change page. And this is quite annoying on touch interface. And so I set out to create my own snippet. And the first thing in order  is to get rid of all those <span> wrapping class. Then we can add all those class with a simple javascript line:

    <script type="text/javascript">$("nav > ul.pagination a").addClass("page-link");</script>

    The full snippet can be found here: https://gist.github.com/truongan/b302641169e98f8a88b62a9f7d3582ee

    This is definitely not some complex hack. But since the problem is so subtle that it slips pass my notice for months, I thougth it would worth the effort to take note in case I ran into this problem sometimes later.

     

  • Something I learnt about openssl

    I’ve been starting to use vestacp to manage my server. Mostly because it’s open source and simple design. But recently it’s SSL feature just… fail. It reject every certificate I throw at it, either from Let’s Encrypt or self sign. So after many lazy-ish hesitant, I decided to dig in.
    Turn out that vesta use openssl extensively to check and verify certificate before enable them. In the file func/domain.sh it has function is_web_cert_valid with this snippet of code:
    openssl s_server -quiet -cert $ssl_dir/$domain.crt \
    -key $ssl_dir/$domain.key >> /dev/null 2>&1 &
    pid=$!
    sleep 0.5
    disown &> /dev/null
    kill $pid &> /dev/null
    check_result $? "ssl certificate key pair is not valid" $E_INVALID

     

    This start a dry run ssl server using openssl feature. And if this dry run result in any abnormal return code, the certificate got reject. But openssl by defaults start its testing server using port 4433, this is also the default port for ssl torrent use by deluge with libtorrent < 1.1. Since I got deluge autostart, openssl can never got hold of port 4433 and quit. And thus vesta reject all of my generated certificate.

    Now I find no way to disable port 4433 in deluge. That feature seem to have been assigned to deluge 1.4 milestone, some said of install libtorrent 1.1 (which turn off ssl torrents by default), but that’s too much of a hassle. Fortunately, openssl can change its port, so I edit line ~340 in file funct/domain.sh and add one argument to the openssl command:-accept 44333

    From

    openssl s_server -quiet -cert $ssl_dir/$domain.crt \
    -key $ssl_dir/$domain.key >> /dev/null 2>&1 &

    To:

    openssl s_server -quiet -accept 44333 -cert $ssl_dir/$domain.crt \
    -key $ssl_dir/$domain.key >> /dev/null 2>&1 &

    And that seem to do the trick.