Quickly recreate SQLite database structure
Here you’ll find an example (and some tips) of an extremely easy PHP code for recreating SQLite database. It can also be used to execute any SQLite query (or serie of queries) stored in a external file.
Here you’ll find an example (and some tips) of an extremely easy PHP code for recreating SQLite database. It can also be used to execute any SQLite query (or serie of queries) stored in a external file.
If you’re still lurking in the darkness of writing code with pure PHP and not using any framework then in this post you can find some nifty function, useful for drawing a HTML list boxes.
Basically it tries to render (draw) a <select>
element basing on input data provided in $source
variable. It can be either a list (key=>value) or string, where values and items’ texts are separated with delimiter. Such string can be provided directly or read from file. In this case you only provide path to a file (source of data).
Read More “Simple function for drawing HTML dropdown list from various sources”
Basic Yii application’s route consists of controller and action. Sometimes you have to add an extra separation layer, to group controllers and actions belonging to separate groups. Not everyone know, that you don’t have to use modules for this purpose. Controllers subdirectory can also be a considerable option. For me, this was a nifty discovery, so I decided to write this down as a personal memo.
Adding a omnibox shortcut to quickly search some site or language reference isn’t a hard task and it is discussed in thousand of blogs. However, by an accident I have found something better — an ultimate solution to PHP shit-littering and cretinism.
Read More “Searching PHP.net using Chrome omnibox”I’ve set myself quite big goal. To setup:
To achieve my goal, I needed a bit tweaked version of WordPress (network) plus a bunch of plugins.
Read More “Multi-site multi-language Markdown-styled WordPress network”Here are most important issues, that I ran into (and resolved most of them) when installing and using WordPress MU Domain Mapping plugin, which allows to use different top-level domains with WordPress Network (WordPress base installation, without this plugin, only allows subdomains to be used).
Read More “Some issues on WordPress MU Domain Mapping plugin”
I wanted to prove myself, that writing WordPress plugins isn’t very hard task. Or, actually, that this can be really, really easy. So I came with this example. This is as simple as possible plugin example. It currently does nothing else except for locking entire front-end of your site for not registered users.
There are many ways to remove Admin Bar that popus up on every page since WordPress 3.1. You can use a plugin or manually edit some PHP files. But most of the sources (and users) forgets that the easiest way is to use proper setting in user profile (works only for frontend).
For people, that uses their Kindles really hard, had them rooted and do all the magic around, this post might be more than painful obvious. For me — just a simple reader, who uses Kindle only for really reading some books, from time to time, finding these shortcuts was not that easy, so I decided to write them down, at least for my personal use.
I love WordPress, but the worst thing about it is that it is written with the most shitty code, I have ever seen.
WordPress development started years ago, and though during past years object-oriented programming has become de facto standard, WordPress still remains full of shit code and shitfull coding techniques. I can understand it about core code. After all — rewriting whole WordPress to OOP could be too big piece of cake. But I completely can’t understand it, why plugin’s authors follows this and write their plugins with pretty much the same shit code?
In this situation, any attempt of making things better is very welcomed (at least by me). The Object Oriented Plugin Template Solution plugin (or actually — plugin template), I ran into today, sounds like such promising star in a dark, dully sky of shit-code.
I recommend this plugin template to every WordPress plugin author. Even though it’s pretty new (published today) it looks very, very promising.
Just a small notice, if you’re ever going to send a Yii application through Gmail. Make sure, that you browse archive, that you’re about to send, and delete all *.bat
files from framework
folder. If you miss that, Gmail will refuse to send email with such attachment, due to “executable file inside”.
Pity is, that this error pops up after attachment is uploaded to Gmail. An archive containing full framework code can take 10 MB or more and can waste some time to attache it to Gmail.
I was faced with a problem of picking a good photo manipulation library. Either client-side or server-side. Both for working with my newest Yii project. This article is a summary of my quick research in this field.
All JavaScript libraries works on Canvas, so require HTML5 and Canvas-enabled browsers. Most modern browsers supports both of them in newest versions.
The only PHP image manipulation library works mostly on uploaded image.
Yesterday I took a part in interview for PHP developer position. My interview task was to solve fifteen questions in quite simple test. One of the questions was to decide if given code sample be treated as unsafe and in which conditions.
I gave a wrong (as it turned out) answer and the argumentation from the intervieerw was quite surprising for me in the first time. Finally I realized my mistake.
Read More “When PHP code should really be treated as unsafe”
There are many 3rd party applications to manage your Kindle devices. After trying a few of them (yes, Calibre sucks the most!), I felt in love with Kindle Collection Manager. This article gives an outline of my reasoning plus provides some thoughts on the program itself.
Read More “A quick overview of Kindle Collection Manager [updated]”I’m using CMarkdown
class to render Markdown-formatted texts stored in separate files (more details in this blog post). And I’ve run into issue with links in Markdown pointing to a different controller then current one.
This article provides some solution for this problem.
In Yii main application is actually a module (core one) so each module configuration actually shares nearly everything what you can put to main application’s configuration file.
Thus, you can configure any Yii module, just as you would do with your main application. The only difference is that you don’t use external configuration file, but CModule::configure()
function instead.
Read More “Alternative module configuration that does not affect main configuration”
Out of this post I have extracted a simple function, that it is said to catch over 97% of mobile browsers available on any mobile devices, people are using in the world. Regular expression used inside detection function is so twixed, that I’m ready to believe, that this is true! :] Wanna give it a try on your mobile device? :>
By using five separate PHP functions, in correct order, you can easily pass (code and decode) entire page’s URL as a parameter of any other script call, redirect etc. And be sure that it will be read (decoded) correctly, no matter, how long your URL is or what kind of characters it is using.
You can encode any URL (current page, last visited page or any otherwise important) and pass it in another URL in the way that your user won’t notice that you’re actually passing an URL.
Presented solution can potentially be used as URL shortening service. Generated URLs aren’t that short (as maybe expected), but for really long URLs it does provides some shortening.
Read More “Passing current or last page full URL as a part of URL”
You can use CMarkdown class as typical Yii widget:
[code language=”php”]
<?php $this->beginWidget(‘CMarkdown’); ?>
_Markdown_ *example*
<?php $this->endWidget(); ?>
[/code]
or directly as a function:
[code language=”php”]
$text = ‘_Markdown_ *example*’;
$md = new CMarkdown;
echo $md->transform($text);
[/code]
That’s pretty much everything, folks!
Well saying “CMS” means a huge over-interpretation here. This article shows how to actually write the quickest and the simplest possible rich-text page content render for rendering Markdown-formatted texts stored in separate .txt
files.
The entire article is actually a single Yii action plus an example on how to call it.
Read More “The simplest possible CMS with CMarkdown and Yii”Here is an example on how to convert CActiveDataProvider
to a simple associative array.
[code language=”php”]
$dataProvider = new CActiveDataProvider(‘Users’);
$data = array();
foreach($dataProvider->getData() as $r)
{
$rowArray = array();
foreach($dataProvider->model->tableSchema->columns as $c) $rowArray[$c->name] = $r[$c->name];
$data[] = $rowArray;
}
[/code]
Columns names are read from table schema, so you don’t have to know table (model) structure to use this.
By default, Yii renders all forms with field’s labels not containing colon after label. This may be unwanted effect for some. The easiest way would be to change field’s label to contain that missing colon. But, that would produce an even more unwanted side-effect of having that colon included (as part of field label) in error message, when validation fails. Here is my simple workaround for this problem.
General code completion in NetBeans works quite good (expect for its speed), but since NetBeans was made for Java and has only “added” support for PHP then it has some issues code completion for PHP and for coding in Yii framework it fails nearly completely.
Here you’ll find approach to fix this and make Yii developers using Netbeans life a little bit easier.
I was looking for a good colorset generator to plot many polylines on Google Maps in nice color schemes.
Colorbrewer turned to be the best one for me.
You can use this generator for any purpose of course, but it seems to be designed for maps coloring in general.
I was looking for a JavaScript code that will check, if passed variable is a valid JSON, no matter, if it is an object or string. I failed with that, because I only found separate solutions for either object or string. Though its authors claimed that they work fine for both objects and strings, as simple check found out this is not true.