rss

Warning: Use of undefined constant yes - assumed 'yes' (this will throw an Error in a future version of PHP) in /homepages/26/d285632327/htdocs/blog.smartwebsitetips.com/wp-content/themes/wp-prolific/index.php on line 25

Warning: Use of undefined constant yes - assumed 'yes' (this will throw an Error in a future version of PHP) in /homepages/26/d285632327/htdocs/blog.smartwebsitetips.com/wp-content/themes/wp-prolific/banner468.php on line 1
0

Flow Types on a React Redux project

again about Flow.
 
I have finished setting up Flow types on our front-end repo that has about 100K lines of code.
 
Some afterthoughts.
 
1. Flow is hard… it is fuckin hard.
2. Without a good mentor one would struggle badly while adding Flow types
3. Flow is fuckin awesome! I don’t regret about the time I spend on bringing it to the board. I found lots of ‘hidden’ bugs while adding types.
4. Flow has known issues and although they are known, that does not help you find the errors easily
-sometimes it shows error in another place.
5. Flow sometimes forces you to add more code on functions just to get better understanding of what’s going on inside.
 
If anyone of you would be doing this kind of task, ask me, and I’ll help in moving fast.
 
Our project included.
-react, redux, thunk, reselect and a lot more…
0

Facebook Audience Network Ads on Desktop – Instant

Hi, today I’ll tell you how to make Audience network ads work on Desktop traffic. Sometimes you don’t have Adsense option, but you want to monetize your desktop traffic also.

So here is the right way to do it.

  1. Open Placements on your Facebook application page.

 

2. Click on “Create Ad Placement”

audience network instant Facebook

 

3. Name your ad, and select “Native” in the drop down list.

audience-network-instant-Facebook

 

4.Then Click on the “Get Code” button

audience-network-instant-Facebook-5

 

5. Click on “Native” and choose “Banner”

audience-network-instant-Facebook-5

 

6. That’s it, copy your iframe code and paste it on your website.

audience-network-instant-Facebook-5.1

 

This way you will be able to track bock desktop and mobile conversions on a separate placements, and will be able to monetize desktop traffic with Facebook Audience Network and instant articles.

 

 

 

0

JavaScript Aync Await or still Bluebird?

WOW finally we can use async await in JavaScript. A long-long waited feature! But wait! Does it have all the nice things we used to have in Bluebird Promise chain? Well let’s have a quick look at an error handling.

I have designed a function theRejector that is an async function and if you pass an argument “2” it will reject the promise.

So I wanted to test if async [] is equivalent of Promise.all([]). But looks like the answer is NO!

In case of Promise.all all rejections are handled by final catch. But in case of async [] => NO.

Try yourself and propose a solution.

Test is run on Node v7.9.0 version.

 

const Promise = require('bluebird')

const theRejector = async (n) => {
  console.log('start f ' + n)
  if (n === 2) {
    await Promise.delay(1000 * 1)
    return Promise.reject('sik')
  } else {
    await Promise.delay(1000 * 3)
    console.log('end f ' + n)
  }
}

const testRections = async () => {
  // this throws unhandled rejection
  await [theRejector(1), theRejector(2)]

  // this throws rejection that is handled by catch!
  await Promise.all([theRejector(1), theRejector(2)])
}

testRections().catch(console.error)

 

0

WordPress Performance Issues in core code.

Hi there, while optimizing performance of one of our websites I came across this query. Query looks for recently published post and, WordPress runs this query very frequently. So on a big database it causes huge problem. Below I’ll show why.

SELECT post_date_gmt
FROM wp_posts
WHERE post_status = 'publish'
AND post_type IN ('post', 'page', 'attachment')
ORDER BY post_date_gmt DESC
LIMIT 1

This query works very slow on a database where I have 500K records in wp_posts table and it weights around 3GB.

On wp_posts table I have compound secondary index “post_status—post_type—post_date_gmt“.

And the reason it works slow is that it uses index and filesort. All of us know how expensive operation is filesort for mysql.

I looked through the code and found that function hardcoded in the source of WP, here it is:

_get_last_post_time()

But if you look carefully, you can see that this query is equivalent of just asking for maximum on the post_date_gmt.

So we can rewrite that function like this.

SELECT max(post_date_gmt)
FROM wp_posts
WHERE post_status = 'publish'
AND post_type IN ('post', 'page', 'attachment')

So this will return the same thing but without expensive ORDER BY and if try to EXPLAIN this query you will see that it uses only the index that I described above, and it avoids filesort. So the result could be calculated very fast!

But the thing is I can’t change WP core and I don’t know whom to ask for fixing this.

If you have any ideas on how can we propose this change, please write. Thank you!

0

Cheap and Easy Setup WordPress Hosting for Your Business

All of my small business client’s websites are hosted on Bluehost. Why? Because they make it very easy to get a new site up and running with their one-click automatic WordPress Blog installation. Yes WordPress, cos all my small business clients are using WordPress for their websites, it’s free, easy to setup and cheap to maintain. Even this current website is using WordPress.

You can use one Bluehost account to host multiple domains and you don’t need to pay more for hosting when you’re ready to start another website. Also, you can enjoy outstanding customer service!

I highly recommend using Bluehost for your first website, and you can get started now at only $3.95/month, which is an exclusive Smart Passive Income reader deal!

0

JavaScript ES6: Generators + Promises

es6-promiseEverything you wanted to know about JavaScript ES6 new features is pretty much covered in this article ES6 in Depth.

My mostly beloved staff that I already use heavily on my NodeJS productions.
Also I found a good usage of generators+promises, I always wanted to have simple solution for if-else switching in long Promise chaining.
Now we can do it via generator+promise combination with Yield keyword. The long story with detailed explanation is here: ES6 Generators and asynchronous javascript

 

 

 

// function shorthand
items.map(item => {
  console.log(item)
})

// generators + promises
getAndSaveCrawlItemSocialScore (clink, type, date) {
  var self = this
  return Promise.coroutine(function * () {
    let link = yield models.links.getLinkById(clink.lid)

    if (!link) {
      yield models.crawlCron.remove(clink._id)
      console.log('No link for CID: ' + clink._id)
      yield Promise.resolve(true)
    }else {
      let score = yield self.grabLinkScore(link)
      yield self.saveLinkScore(link._id, score)
      yield models.links.markAsParsed(link)
      yield self.CrawlCron.markAsParsed(clink)
      yield Promise.resolve()
    }
  })()
}

0

List of WordPress users without role

Here is the SQL that will provide you the list of users that does not have role on your website.

Assuming you have banned some users, with assigning them No Role For this website.

 

SELECT user_id FROM `wp_usermeta` 
WHERE meta_key='wp_capabilities' 
AND meta_value='a:0:{}'

Enjoy!

0

From WordPress to Yii2 password hash migration

Hi, if you are migrating from WordPress to Yii2, and want to maintain existing user base with passwords, then you will probably need this small script.

I have published it on Github wordpressToYii2PasswordMigrate.

This script will check, to see if user has Yii2 password hash or WordPress one. Check is based on password_hash length. If password_hash is not 60 characters, then system tries to validate password via WordPress functions. And if succeed, it will then convert the raw password into Yii2 password hash, generate and auth_key and save into database. So that after first log-in, users will have Yii2 password hash.

0

The most fantastic developer hosting – DigitalOcean

Want a hustle free cheap VPS? Tired of yearly/monthly contracts and big fees?

DigitalOcean is for you. I’m using it currently for 5 big projects as a development server. It’s already three months I’m using it, and I would say that I’m really impressed with fees, speed and features it provides.

You easily shrink it, add RAM, disk space and lot more, without re-installing all your software, simply because it is on cloud. Moreover, you can switch off your dropplets, when you do not work on it, and thus incur less fees!

Worth to mention that it uses SSD drives, which is much much much faster that HDDs.

So if you decide to give a try, please use this link, https://www.digitalocean.com/?refcode=a09aa85a57aa

This link is affiliated, and it will grant me some bonus points.

Enjoy!

0

NextGEN Gallery – The most dangerous configuration

I like WordPress NextGEN Gallery plug-in very much. It has all the nice features that one would need for creating galleries.
And I think it’s the most popular gallery plug-in currently and very widespread, it has over 11 million downloads.

But what I noticed recently, made me worry about my websites and yours! :)

NextGEN Gallery has one configuration option, which is by default enabled, and leaving it enabled, may lead to loss of images.
Configuration is called “Delete Image Files?“, (When enabled, image files will be removed after a Gallery has been deleted).

So imagine, you have installed gallery, put some images. After some time, you just want to experiment or develop website further, and decide to remove gallery plug-in and re-install it, or just accidentally removed the gallery plug-in from the plug-ins page. What will happen? Guess… all your images store in the gallery folder will be deleted!

That’s why I strongly recommend you, right aftergallery installation, go to the NextGEN Gallery other options page (http://yoursite.com/wp-admin/admin.php?page=ngg_other_options) and put this option to “No”.

Here is the screenshot of the options page:

nextgen-gallery-configuration

click to enlarge