Tuesday, 5 April 2011

Оптимизируем процесс работы в консоли

Все привыкли редактировать текст в текстовых редакторах, блокнотах, веб-формах и т.д. В процессе набора текста мы пользуемся привычными стрелками, кнопками «End» и «Home», более опытные зажимают «Ctrl» и стрелками шагают по словам (что, кстати, не всегда работает). И при переходе на консоль мы ориентируемся на те же самые правила, даже не зная, что bash предлагает очень удобные средства и комбинации клавиш, которые очень упрощают работу и минимизируют количество операций для выполнения задачи. К тому же, в bash есть удобные средства работы с историей, масса различных подстановок и других интересных функций. Самые часто используемые мной и любым опытным администратором я и опишу в этой статье.

Для того, чтобы все, описанное мной, заработало, не нужно ничего до устанавливать, не нужно писать скрипты, конфиги и прочие дополнения: все эти средства работают абсолютно одинаково в большинстве современных интерпретаторах bash, работающих на любой UNIX системе.
Мой педагогический опыт говорит о том, что практика — лучший способ понять, полюбить и привыкнуть к новым функциям, поэтому я не стал рисовать голые таблицы, а сделал повествование, и рекомендую в процессе чтения статьи открыть консоль и пробовать все, чем еще не пользовались, руками.  

Monday, 23 August 2010

Get list or array from parameters

Sometimes in a web form, it is useful to allow inputting multiple values to be associated with one name

In some scenarios, a web form can allow inputting multiple values to be associated with the same named field:

<form>
<input name="key" type="text">
<input name="key" type="text">
</form>

The posted url is like: ?key=value1&key=value2
def list = params.list('key')

And also can be used:
def intValue = params.int('paramInt')
def shortValue = params.short('paramShort')
def byteValue = params.byte('paramByte')
def longValue = params.long('paramLong')
def doubleValue = params.double('paramDouble')
def floatValue = params.float('paramFloat')
def booleanValue = params.boolean('paramBoolean')

GSP debug

For debugging GSP pages in Grails is easy to use parameter showSource at the url to show the Java code to spot on the lines with errors.

Monday, 5 July 2010

Grails app on WebLogic 10.x

If you trying to start app and have exceptions in log like this:

ClassNotFoundException: org.hibernate.hql.ast.HqlToken 

Try to add weblogic.xml file with this contents to web-app/WEB-INF:
<?xml version="1.0" encoding="UTF-8"?> 
<wls:weblogic-web-app 
        xmlns:wls="http://www.bea.com/ns/weblogic/weblogic-web-app" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://www.bea.com/ns/weblogic/weblogic-web-app http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd"> 
    <wls:weblogic-version>10.3.0</wls:weblogic-version> 
    <wls:container-descriptor> 
         <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes> 
    </wls:container-descriptor> 
</wls:weblogic-web-app> 

Monday, 28 June 2010

Syntax Highlighting Blogger

There is no Highlighting plugin Blogger

We can add this feature manually using SyntaxHighlighter:

Go to your blogger settings page ->  Design-> Edit HTML
And add following text before string "</head>"

  
Now we can add to post html code
{
  // code
  println "Hellow World!" 
}

And have a result:

{
 // code
 println "Hellow World!" 
}

If you need more language brushes, you can find the information at the alexgorbatchev.com site

Thursday, 24 June 2010

Code tag in Blogger

Code tag is absent in Blogger

For solving it  I used the Quote (<blockquote>) and simple CSS

Result
Css code can be simple add to blog layout:
Blogpost->Design->Template Designe->Advansed->Add CSS
I have  added the following code
blockquote {font-size:14px; margin: 10px 0 10px 20px; background-color: #F9F9F9; border:1px solid silver; padding:5px}

Image preview with jQuery

ecently I had a project that demanded a rollover image preview like:

The solution is very simple. I have used the JS code
But, in the project we have the image tag instead of image url and I cant just write:
<a href="http://www.cssglobe.com/" class="screenshot" rel="screenshot.jpg">Css Globe</a>

It will be like:

<a href="http://www.cssglobe.com/" class="screenshot" rel="<img width=" height="125" alt="Css web templates" src="http://s3.buysellads.com/1239599/2123a9e0c268292ef982e08c774473a3-1245081692.gif" />">Css Globe</a>

But it is wrong HTML code

The Solution:


In Grails App do picture.encodeAsURL()

In HTML now we have:
<a rel="%3Cimg+alt%3D%22%22+src%3D%22http%3A%2F%2Fi027.radikal.ru%2F1005%2Fce%2F6cee5e56d9bf.jpg%22+%2F%3E" class="screenshot" title="undefined" href="http://www.cssglobe.com/">Css Globe</a>And we should decode it by JS. The result js code is:

/*
* Url preview script
* powered by jQuery (http://www.jquery.com)
* written by Alen Grakalic (http://cssglobe.com)
*/

function screenshotPreview(){
xOffset = 10;
yOffset = 30;
jQ(".screenshot").hover(function(e){
this.t = this.title;
this.title = "";
var c = (this.t != "") ? "
" + this.t : "";
var pic = URLDecode(this.rel);
jQ("body").append("
"+ pic + c +"
");
jQ("#screenshot")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px")
.fadeIn("fast");
},
function(){
this.title = this.t;
jQ("#screenshot").remove();
});
jQ("a.screenshot").mousemove(function(e){
jQ("#screenshot")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px");
});
};

function URLDecode(encoded)
{
var HEXCHARS = "0123456789ABCDEFabcdef";
var plaintext = "";
var i = 0;
while (i < encoded.length) {
var ch = encoded.charAt(i);
if (ch == "+") {
plaintext += " ";
i++;
} else if (ch == "%") {
if (i < (encoded.length-2)
&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
plaintext += unescape( encoded.substr(i,3) );
i += 3;
} else {
plaintext += "%[ERROR]";
i++;
}
} else {
plaintext += ch;
i++;
}
} // while
return plaintext
}

$(document).ready(function() {
screenshotPreview();
});