Find and block unsafe content on your wordpress installation

For some reason, my WP installation decided to load some files via http instead of https

Screen Shot 2018-11-12 at 3.28.59 PM.png

To find out which file it is, I used the Javascript consoleScreen Shot 2018-11-12 at 3.29.39 PM.png

It’s wp-emoji in this case, and I don’t use emojis on my site, so I decided to block it by adding this to my theme’s functions.php

 

remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );

 

How to install zip extension for PHP7

Specifically for LAMP stack / webmin

First, install the module

sudo apt-get install php7.0-zip

Then restart the web server

sudo service apache2 restart
sudo service nginx restart

That’s it!

Javascript idioms

From Zoltan Kochan, author of pnpm

 

Double exclamation

Prefixing anything with !! converts it to a boolean.

var foo = 0
console.log(!!foo)
//> false

Essentially it is a shorter way to write Boolean(foo).

Converting arguments to array

The arguments object can be used to access the arguments passed to the function. However, it is not an Array so it doesn’t have Array properties except length. The Array.prototype.slice.call(arguments) idiom is used very frequently to convert the argument’s object to an actual array.

(function() {
  console.log(arguments instanceof Array)
  //> false

  var args = Array.prototype.slice.call(arguments)
  console.log(args instanceof Array)
  //> true
})()

Assigning default values

function foo(opts) {
  var msg = opts.message || 'Hello world!'
  console.log(msg)
}

// instead of
function foo(opts) {
  var msg = opts.message ? opts.message : 'Hello world!'
  console.log(msg)
}

More examples of interesting || and && usages can be found in the 12 Simple (Yet Powerful) JavaScript Tips article.

Converting to array if not already

var totallyArray = [].concat(value)

//instead of
var totallyArray = value instanceof Array ? value : [value]

Converting strings to number

var foo = +'12.2'
var bar = +'12'

// instead of
var foo = parseFloat('12.2')
var bar = parseInt('12')

Checking if an array includes an element

if (~[1, 2, 3].indexOf(2)) { console.log('includes') }

// instead of
if ([1, 2, 3].indexOf(2) > -1) { console.log('includes') }

There are some other usage examples for the tilde operator as well in The Great Mystery of the Tilde(~).

Writing multi-line strings

var multiStr = [
  "This is the first line",
  "This is the second line",
  "This is more..."
].join("\n");

// instead of
var multiStr = "This is the first line\n" +
  "This is the second line\n" +
  "This is more...";

Looping through an array

It can be used if order is not important

for (var i = arr.length; i--;) {
  // ...
}

// instead of
for (var i = 0; i < arr.length; i++) {
  // ...
}

setTimeout(func, 0)

JavaScript code runs on one thread. Calling setTimeout with 0 allows to schedule a function to run after the current event loop tick.

setTimeout(function() {
  console.log('log message from next tick')
}, 0)

console.log('Hello world!')
//> Hello world!
//> log message from next tick

Fetching data from the web with C#, the easy way (1-liner)

I don’t know why the top results from Google always involve more than 10 lines of code and loads of comments when actually you can just do this:

byte[] Data = new WebClient().DownloadData(FrameURL);

You can try DownloadString and DownloadFile based on your requirements

The webgame storm

It was not so long ago the web was still a bunch of text-only HTML without CSS and stuff. Now it can open your documents, let you communicate, catch the latest scoop on entertainment, then why not play games on it?

Before, the web was designed to deliver text-based content. Most related technologies are also text-oriented: CSS, XML, AJAX, and JavaScript. But now, as browsers have got more mature and text features are saturated among competitors, there goes the performance race. JavaScript got faster, as JIT compiling and other interpreted language technologies are improved. Now games are feasible and the web game industry began to rise. GIF for sprites, PNG for effects, JavaScript is capable of image processing is far than enough to make a game possible.

For web game, you know I don’t mean those simple flash games you play at work to make your boss mad, but instead role playing games that will take you an indefinite amount of time to play, just like Lineage or Ragnarok. Those game is also a kind of society, where players can communicate with each other, thus games could be considered a part of the 2.0 hype.

This is far from being an exhaustive review of web games, but instead the experiences I have with them.

Gaia online

Possibly the most influential web game now is Gaia Online, a collection of game and community activities. As the biggest, it also causes most controversial problems (say pedophilias). It’s not a single game with a single story but it does have role playing elements like quests. Nevertheless, it’s nice interface and huge community is quite attractive to those who have nothing else to do. Gaia also sure inspired a lot of modern web games.

Gaia online town

Gaia online town

Image: CNET

Gameforge

Gameforge is an influential game maker emerged recently. Though their games are pretty much in beta stage, their international approach (provides as many language as possible) seem to be effective. Based on the number of new games they release each year, it’s clear that they made quite a lot selling enhancements to their games. Those enhancements does not provide a real advantage over those who don’t have time, but that’s a right move: they attracted a huge number of free players that even the slightest advantage will have effect toward thousands of another players.

Most of their games are real-time. That is, moving armies or explore and area will cost you hours in real life. It’s up to you when to care about the game but the more you care about it, the more successful you are. It’s like the Japanese’s Tamagochi where your chicken is now a gladiator or an empire :P.

They also don’t have a nice interface like other producers. I’m unsure why but all their games look pretty clumsy to me

Ikariam is the most recently Gameforge game I played. You can build cities in an ancient Rome theme. You build cities on islands with a specific resource. Among them: Wine, Marble, Crystal and Sulphur. You can freely develop your empire, research to improve technologies, build troops to defend your empire or wage war at another, trade and exercise diplomacy with other empires. Addictive and time-consuming. Though you don’t have to wait for the buildings to build, you are always at risk getting attacked if you are not prepared; and even if you did prepared, you might get attacked by someone stronger anyways :p

Ikariam city view

Ikariam city view

Before, I have also played Gladiatus, where you play the role of a Roman gladiator. You can fight others, work to earn money, do quest to gain fame etc. Simple interface, you don’t actually see the gladiators combat and I get bored after a while doing repetitive actions: work – quest – explore – buy / sell items – dungeon – work, and get bashed by stronger players (though their levels are lower). It’s still a mystery how they get so many gold to win at auctions ;).

Other Gameforge games include bitefight, kingsage and ogame.

Though those games are of great entertainment value, Gameforge is quite stingy to rely that much on volunteers to exercise control on the game. Even when it cost them almost nothing hiring those volunteers (they pay by in game bonuses), they are still reluctant to hire some more. It’s funny when they don’t allow multiple accounts in their rules but doesn’t have any automatic control over user registration. Instead they rely on 5 game operators to ban each of the violating accounts. Imagine when 30% of the server of 10 thousand players decide to go against the rule, what will happen?

Well, that is happening already and it made those games tasteless to me now, since Vietnamese are so clever to dodge the rules to satisfy their deflated self-esteem in games :(. What’s the good for that anyways? Games are games and they still spend hours to fight in game, and then take another hour to fight on the forum. In the end, it turns out that all the big shots are multis 🙂 (Note that multi account players have a huge advantage over those who don’t, say, a 1000% increase in resources by manipulating the clones).

I’m off until those games get better so I can play it the way I want, undisturbed by idiots who have no reasoning capabilities. I’m giving away my accounts for Ikariam and Gladiatus for someone who can take care of them under one condition that I can borrow them sometimes :). My Ikariam account is 4 months old on Gamma and has 3 cities: level 16 -16 -15. The Gladiatus one is somewhere around level 19. Email me if you have inquiries about this.

Aurora blade

A RPG, where you can actually cast spell, do action and handle items, which you once thought it wouldn’t possible without a 2 GB client :P. Its graphics is quite nice though the image compression is somehow flawed (you can see jagged JPGs all around). Nice game with rich content, from monster fighting, quests to game events. Though it’s criticized for copying many designs from Ragnarok and WoW, it still take quite a lot of effort to build this game and integrate all the graphics. Cheers for the Chinese! (IGG is founded by Chinese).

In Vietnam

Though the big guys have developed quite a stand in this business with quality games and strategic moves, smaller publisher and developers still find their foothold somewhere. Sadly, most of the games in Vietnam are still just translations from foreign developers (again, Chinese). Though they employed large advertisement campaign and sexy cosplayers I still find little interest in them. First, they are from China. What’s so great about Chinese games? Or are they paid by the Chinese to accomplish the cultural elimination the Chinese was unable to complete years ago? Second, under their colorful interface, you can barely find the register link (sometimes you actually have to ask to be shown the register link :P).

There are quite a lot of stuff to entertain you on the net already. Web games are still at the beginning of their era. Even though they have come over technical challenges, most of them still don’t fit the average user’s playing habit. For any SimCity fanatic out there, Ikariam is like a disater where your beloved city get ripped of its bone by aliens from the next planet :P. Each of the game has its own strength and weakness, competition between them would be a fun thing to watch in the future.

In Vietnam, I don’t think any of those games will make a difference.

  1. The current economic crisis have driven away some hardcore player. They have to make a living!
  2. There are fewer clients who is willing to buy virtual stuff to support a game.
  3. Unless Vietnamese gamers’ barbaric and lawless attitude is changed, those game won’t attract the more educated classes. Playing along with idiots is pretty irritating. (LEEEEEROY!)

End of another lengthy post 😛