Surfing With Code

Tricks for developers about Java, HTML5, CSS, JavaScript, XML, jSON, deployment, design …

Understanding scopes prefixes in AngularJS custom Directives — abril 6, 2017

Understanding scopes prefixes in AngularJS custom Directives

‘@’ – Text binding / one-way binding. For passing strings. These strings support {{}} expressions for interpolated values
‘=’ – Direct model binding / two-way binding. The model in parent scope is linked to the model in the directive’s isolated scope.
‘&’ – Behavior binding / Method binding. For passing a method into your directive’s scope so that it can be called within your directive.

JavaScript: Escaping Special Characters — abril 3, 2017

JavaScript: Escaping Special Characters

Every programming language has it’s special characters – characters that mean something special such as identifying a variable, the end of a line or a break in some data. JavaScript is no different, so it provides a number of functions that encode and decode special characters.

  • The JavaScript escape function replaces most punctuation symbols with the equivalent hex-codes, but was found to be inadequate when it came to UNICODE character encoding and has been superseded by the encodeURI function.
  • The encodeURIComponent function is an extension of encodeURI, the difference being that it also escapes the following characters: , / ? : @ & = + $
  • The htmlentities function escapes characters which have special meaning inside HTML by inserting HTML entities in their place (eg. & in place of &). See our article on ASCII Character Codes for more details.

All functions have a complementary ‘decode’ function that pretty much does the opposite.

Example:

The apostrophe character: ‘

escape: \’

htmlEntitie: '

JavaScript: How to remove properties from Objects — marzo 20, 2017
[Quick trick] Remove or empty a column from a table in SQL — febrero 15, 2017
[Quick trick] How to View Which Postgres Version is Running — febrero 6, 2017
Groovy: the Elvis Operator ?: — agosto 25, 2016

Groovy: the Elvis Operator ?:

Groovy is good at shortening normal Java statements. The Elvis operator is to shorten the ternary operator. If we have a sensible default when the value is null or false (following Groovy truth rules) we can use the Elvis operator. And why is it called the Elvis operator? Turn your head to the left and you will know.


def sampleText

// Normal ternary operator.
def ternaryOutput = (sampleText != null) ? sampleText : 'Hello Groovy!'

// The Elvis operator in action. We must read: 'If sampleText is not null assign
// sampleText to elvisOuput, otherwise assign 'Viva Las Vegas!' to elvisOutput.
def elvisOutput = sampleText ?: 'Viva Las Vegas!'
<div class="line number0 index0 alt1 break"></div>

Via: MRHAKI blog

Keyboard locks in IntelliJ IDEA on Ubuntu 14.04 — julio 6, 2016

Keyboard locks in IntelliJ IDEA on Ubuntu 14.04

When you use Intellij IDEA 13 on Ubuntu 14.04 and from time to time the keyboard completely (yep, completely, it’s not about shortcuts) locks in IDEA. You still can do anything you want in IDEA with your mouse, also you can use the keyboard everywhere else except IDEA. And it can be fixed only by restarting IDEA so far… Howewer, you have a better solution:


ibus-daemon -rd

Enjoy!

Why enclose JavaScript code in a functions? — febrero 2, 2016

Why enclose JavaScript code in a functions?

Lately, specially with the last JavaScript frameworks, it is common to see the JS code (or files) enclosed in a function as follows:

(function() {
... all javascript code for the file ...
})();

Variables in Javascript have function scope. You’re wrapping your code in a function in order for it not to clobber the global namespace with tons of variables, which may lead to bugs later on when different code is added. E.g.:

// module 1
(function () {
var foo = 'bar';
...
})();

// module 2
(function () {
var foo = 'baz';
...
})();

By this way there is no problems, because both modules have their own variable scopes.

Integrate Spring and Webapp project — enero 26, 2016

Integrate Spring and Webapp project

Spring can be easily integrated into any Java-based web framework. All you need to do is to declare the ContextLoaderListener in your web.xml and use a contextConfigLocation to set which context files to load.

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>

	<listener>
	<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener> 

 

Then, you can use the WebApplicationContext to get a handle on your beans or handle them using “@Autowired” annotation

 

 

 

Set different loglevel for different packages/classes —