Просто ни о чем
Эх, поразмыслил тут и понял - писать только о науке и технике просто скучно. А тем более скучно писать всё это на английском языке. Да и вообще - что-то в последнее время всё меньше хочется видеть англоязычных продуктов вокруг себя - то ли старею, то ли просто английский надоел, то ли просто не хватает русского в моем окружении (а живу я на данный момент среди финнов, которые по понятным причинам русского не знают).
И как результат моего конечного остервенения - вот этот пост на русском языке и даже не про технику, а про вообще (я думаю уже можно было заметить насколько никчёмен и бессмысленен сей пост). Собственно, про вообще хочется много сказать, но времени как всегда мало. А почему мало? Ведь не потому же что в сутках 24 часа?! Я более чем уверен, что будь в сутках часов сорок - ничего бы не поменялось - времени все равно бы ни на что не хватало (тут как в старом анекдоте про Винду - "В: а сколько Виндовс места на диске занимает? О: сколько находит столько и занимает").
Localizing a WPF application
I know, Google knows so much about this, yet still, no clear and simple step-by-step guide. So here it goes:
- Download LocBaml tool here
- Compile it and get the LocBaml.exe
- Open your project file with Notepad.
- Add the following there: <UICulture>en-US</UICulture> under all <PropertyGroup> tags (for all build configs that is).
- In your XAML files add x:Uid="someUniqueUid" to any element you want to localize.
- Build your project.
- Navigate your explorer to the build folder - you will see that it has a new subfolder called en-US. Inside you will find a file - YourProject.resources.dll
- Copy the binary of your project (e.g. YourProject.exe), LocBaml.exe and any referenced project binaries into this en-US folder.
- Open a command line prompt in this folder (under Windows seven you can press [Shift] + Right click and choose the command prompt window from the context menu).
- Run the following: locbaml /parse YourProject.resources.dll /out:YourProject.txt - a human-readable text file will appear in the folder.
- Edit the text file (translate the values in it). Excel is your best option - open the file from Excel menu and it will ask you if you want to treat tab symbols as text separators).
- Run the following after you localized the text file: locbaml /generate /trans:YourProject.txt /out:..\ru-RU /cul:ru-RU YourProject.resources.dll (replace ru-RU with the culture you are localizing into).
- Now all you have to do is to set the CultureInfo for your application thread like this:
var cultureInfo = new CultureInfo("ru-RU");
System.Threading.CurrentThread.CurrentCulture = cultureInfo;
System.Threading.CurrentThread.CurrentUICulture = cultureInfo;
And you are done. You app should be localized now!
Loading Assebmlies with references
Recently I encountered this thing again and had to look for an answer for quite some time (again
).
Just an example of the assembly structure I wanted to have:
- Main.exe
- lib (folder)
- Shared.dll (used by Main.exe, Plugin1.dll and Plugin2.dll)
- Plugin1.dll
- Plugin2.dll
- lib (folder)
The answer – open up your app.config from Main.exe project and add the following (under <configuration> tag):
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="lib"/>
</assemblyBinding>
</runtime>
That is it. Now it will also search for referenced libraries in the lib folder
CodeIgniter – Cart crap with Cyrillic characters
Ok, now this is so ridiculous that I have to blog about this even though I do not want to. CodeIgniter just blew my mind some time ago when I upgraded to 1.7.2 for the new Cart library. I realize, that it is a basic functionality, yet still... It does not support cyrillic characters in the product name! It is freaking 2009, almost 2010 and one of the most popular MVC frameworks does not support cyrillic? And I bet any other "strange" characters too, because basically they have a filter there with a regexp:
var $product_name_rules = '\.\:\-_ a-z0-9';
Now that is some serious shit!
Anyway, if you have trouble with the same thing - doing non-latin chars in product names just find and comment out the following part from system/libraries/Cart.php:
if ( ! preg_match("/^[".$this->product_name_rules."]+$/i", $items['name']))
{
log_message('error', 'An invalid name was submitted as the product name: '.$items['name'].' The name can only contain alpha-numeric characters, dashes, underscores, colons, and spaces');
return FALSE;
}
Also, if you are using a database table for your sessions - do not forget to check that the user_data field uses UTF-8 as its encoding (otherwise it won't let cyr chars into the field).
Enough ClearType! Go GDI++!
Did you ever want to replace the ugly ClearType with something better? I know I have. And my prayers have been answered - meet GDI++ - the solution to all your font problems. Enough words, see it in action (this is Verdana, btw):
Well, I think that the difference is pretty obvious. So if you are ready to start you new font life - go here and download the file named gdi0870.zip (404kb). Extract anywhere you want and launch gditray.exe. Choose 'enable' from the context menu of the tray icon and voila - your font are rendered without the help of that ugly, ugly ClearType.
RoR: Session / login management
This is basic yet not obvious in Ruby on Rails - I've been looking for info on this for a long time (a long time for this problem is anything more than 5 minutes).
So, this is the way you make sessions/logins work in ruby:
class SessionController < ApplicationController
def login
@session['logged'] = true
end
def logout
@session['logged'] = false
end
end
The @session variable is available anywhere. Use it anywhere. For example you could come up with the following view showing whether the user is logged in:
<p>Logged in: <%= @session['logged'] %> </p>
And that is it. Anything beyond that (like adding a User model etc.) is out of this post's target. There are many articles on those things yet no clear explanation where to find and how to init a session. As you can see - the answer is clear - you don't
The session is already there. Just start using it.
Basic CSS layout
The basic CSS layout I use in my work is plain simple - header, sontent, sidebar and footer.
The HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>My page</title>
<base href="http://localhost/" />
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div id="wrap">
<div id="header">
Header
</div>
<div id="content">
Content
</div>
<div id="sidebar">
Sidebar
</div>
<div class="clr"></div>
<div id="footer">
Footer
</div>
</div>
</body>
</html>
And the CSS is very simple:
#wrap { width: 960px; margin: 0 auto; }
#header { }
#content { width: 700px; float: left; }
#sidebar { width: 260px; float: right; }
#footer { }
.clr { clear:both; height:0px; overflow:hidden; }
This is it. This code will show a simple page which is ready for hardcore modification. I know this is pretty basic yet it is one of the most used code snippets in my IDE. Good luck!
Image / file upload with CodeIgniter
Image upload can be a pain in the *ss. And even though CI has a lot to offer (in the means of documentation) it still lacks a direct copy-paste code on their website so that people can just put it into their controller and use away.
Here we will have:
- Image upload form with 5 images
- And a controller function that will upload those
- Thumbnails will be there too
Komodo Edit tools – add style.css and reset.css
Good morning, planet. Today I am going to share a very useful script I am using in Komodo Edit (it automates adding style.css). It is very (!) simple yet very effective for me and, probably for others who are doing a lot of HTML files and face a problem of repetitive actions.
This thing works as follows (the use case):
- You create a new HTML file in komodo and save it in some directory.
- You double-click the script in the Komodo Edit toolbox.
- The script adds the following folders/files to the project (paths relative to the file currently in editor!)
- css/
- css/style.css
- css/reset.css
- Also the file adds the following HTML code at the cursor in current opened file:
Voila. The needed action is done.
How-To: Create a horizontal menu
This is a tutorial on how to create a fully costomizable horizontal menu. Why another menu how-to? Well, mostly because there are situations when there are no suitable google results (based on my experience) and you have to come up with something yourself.
These are the features we will try to get into our menu:
- It will be horizontal
- It will have splitters (made with images)
- It will have active class for rollover / selected item (background change)
- Menu items will be of different size
This code works for Internet Explorer 6+, Firefox 2.0+, Opera 9+, Safari (at least on Safari 4 - tested on Windows version of it).
Here is a mockup that we have:
Menu mockup
NB! If you just want to see how to do it - go here for the demo / full code.
