
Using keyboard shortcuts in Javascript - CatsWhoCode.com Keyboard shorcuts on the web, let’s talk about it The most important thing to think about when implementing Javascript keyboard shortcuts on a web app is to avoid redefining shortcuts provided by the client’s browser. Imagine that you’re using a web app, you want to close the tab by pressing Cmd+W, and the web app trigger an action, just because the developer redefined a keyboard shortcut used by your browser…How annoying. As you may already know, Javascript have lots of useful event listeners. Keyboard codes are simple code consisting of 2 or 3 numbers. For a full reference of keyboard keys, scroll down to the end of this post. Examples In the following example, we’re simply going to verify the key pressed down by the user. First example, without JQuery: var isCtrl = false; document.onkeyup=function(e) { if(e.which == 17) isCtrl=false; }document.onkeydown=function(e){ if(e.which == 17) isCtrl=true; if(e.which == 83 && isCtrl == true) { alert('Keyboard shortcuts are cool!')
RegExp - MDC Description Literal notation and constructor There are two ways to create a RegExp object: a literal notation and a constructor. The literal notation takes a pattern between two slashes, followed by optional flags, after the second slash.The constructor function takes either a string or a RegExp object as its first parameter and a string of optional flags as its second parameter. The following three expressions create the same regular expression object: const re = /ab+c/i; // literal notation // OR const re = new RegExp("ab+c", "i"); // constructor with string pattern as first argument // OR const re = new RegExp(/ab+c/, "i"); // constructor with regular expression literal as first argument Before regular expressions can be used, they have to be compiled. The literal notation results in compilation of the regular expression when the expression is evaluated. Use a string as the first argument to the RegExp() constructor when you want to build the regular expression from dynamic input. RegExp()
How Regexes Work Mark-Jason Dominus Copyright © 1998 The Perl Journal. Reprinted with permission. This isn't an article about how to use regexes; you've probably seen plenty of those already. I'll demonstrate a new module, Regex.pm, which implements regexes from nothing, in Perl. Here's the basic strategy: We'll see a simple kind of `machine' that reads a input, one character at a time, and then, depending on what's in the input and on the various wheels and gears in the machine, either says `yes' or `no'. When our program wants to see if matched //, it'll do something like this: Look at . Maybe this sounds bizarre, but bizarre or not, it's what Perl does. Machines We're on a tight budget here, so our machines will be made of circles and arrows instead of wheels and gears, which are expensive. Let's see if this machine says `yes' to the string "abaa". We start by putting a penny down on the M circle, because the M circle is the start circle. Next the machine will read the "b". Blank Arrows Rules Again Lies
Toolbox - Regular Expression Tester - Test and Learn Regex Search Syntax v1.31, 2006.05.01 by Robert Giordano Regular Expression Syntax: [agk] matches any one a, g, or k [a-z] matches any one character from a to z [^z] matches any character other than z [\\(\\)] matches ( or ) (in javascript, the escape slash must be escaped!) . any character except \n \w any word character, same as [a-zA-Z0-9_] \W any non-word character \s any whitespace character, same as [ \t\n\r\f\v] \S any non-whitespace character \d any digit \D any non-digit \/ literal / \\ literal \ \. literal . \* literal * \+ literal + \? literal ? \| literal | \( literal ( \) literal ) \[ literal [ \] literal ] \- the - must be escaped inside brackets: [a-z0-9 _.\-\?!] Examples: /\b(gr[ae]y)/ig,"GRay" Replaces any "gray" or "grey" with "GRay". /\b(cat|dog)\b/ig,"pet" Replaces any "cat" or "dog" with "pet". /feb(ruary)? /( ){2,}/g," " Replaces 2 or more consecutive spaces with a single space. /^\s+|\s+$/g,"" Trim white space from both ends of a string. /\b(is)(?! /(.+)((\r? /\b(\w{4})\s? Greedy vs.
Joshua Flanagan - Readable Regular Expressions My main point of focus at work lately has been promoting maintainable code. One of the key tenets is readable code. The single responsibility principle and a low cyclomatic complexity are important, but if you are still using cryptic, prefixed, acronymed, and highly abbreviated identifiers, it is still going to be a chore for the reader to decipher. My slogan: "let's take the code out of source code". I was just listening to Roy Osherove talk about regular expressions on .NET Rocks. A recurring theme brought up was how hard regular expressions are to deal with. It got me thinking that this was a problem worth solving. Inspired by the Ayende's Rhino.Mocks syntax, I created a library that provides a better way to define regular expressions in your source code. Regex socialSecurityNumberCheck = new Regex(@"^\d{3}-? Using ReadableRex (not settled on the name yet...), it would look like: Regex socialSecurityNumberCheck = new Regex(Pattern.With.AtBeginning .Digit.Repeat.Exactly(3) .AtEnd);
Underscore.js Underscore is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects. It’s the answer to the question: “If I sit down in front of a blank HTML page, and want to start being productive immediately, what do I need?” … and the tie to go along with jQuery's tux and Backbone's suspenders. Underscore provides 80-odd functions that support both the usual functional suspects: map, select, invoke — as well as more specialized helpers: function binding, javascript templating, deep equality testing, and so on. The project is hosted on GitHub. Collection Functions (Arrays or Objects) _.each(list, iterator, [context]) Alias: forEach Iterates over a list of elements, yielding each in turn to an iterator function. Note: Collection functions work on arrays, objects, and array-like objects such as arguments, NodeList and similar. var sum = _.reduce([1, 2, 3], function(memo, num){ return memo + num; }, 0); => 6 Array Functions
Regular Expressions in JavaScript, part 2 - James Padolsey A while ago, when I was just getting used to this insanely complicated stuff, I posted a brief introduction to the world of regular expressions. I’m glad to say that, since then, I have learnt a bunch more about them and how you can make use of them within JavaScript. So, here goes: In JavaScript, there are four string operations that will accept a regular expression as an argument: String.match(), – this method only accepts a regexp as the first argument. The RegExp object has its own methods: RegExp.exec(), – this method is exactly the same as the String.match() method, the only difference being that you pass the string as the argument and the method is run as a member of the regular expression that you’re using to search the string. Because I know no better way to begin, let’s start with a basic example: Validating user input One of the most common uses for regular expressions on the client-side is validating user input. Now, with a regular expression: The ‘i’ that you see is a flag.
The Regex Coach - interactive regular expressions Abstract The Regex Coach is a graphical application for Windows which can be used to experiment with (Perl-compatible) regular expressions interactively. It has the following features: It shows whether a regular expression matches a particular target string. Contents Download and installation The Regex Coach together with this documentation can be downloaded from You should use Windows 2000 or Windows XP with all updates and service packs installed. You also must have the Microsoft runtime library msvcr80.dll installed. If you have a previous version (0.8.5 or earlier) of The Regex Coach installed, uninstall it first before you install the new version! Older versions, Linux, FreeBSD, Mac Beginning with version 0.9.0, there will no longer be a Linux version of The Regex Coach - too few people were using it, and it's simply too much work for me to maintain both versions. There is no Mac version and I have no plans to release one. License The main panes
Buying an iBeacon: Guide to Bluetooth LE Devices Having trouble figuring out all of the options for iBeacons and Bluetooth LE devices? You’re not alone. Every day there seems to be a new device or beacon being launched – and confusing things further, the terms iBeacon, beacon and Bluetooth LE often seem interchangeable. To try to make life slightly easier, this page is your resource and link list for the physical devices called ‘beacons’. Definitions First, however, a few simple definitions: Beacons: A beacon is any device that transmits a signal which allows another device to determine its proximity to the broadcaster. Bluetooth Low Energy: This is the specification for one type of signal that beacons transmit. iBeacon: The term iBeacon and beacon are often used interchangeably. Devices: The list below includes all devices that are capable of Bluetooth LE broadcasting. List of Bluetooth LE Devices Accent Advanced Systems iBks101 are one of a suite of products by Accent Advanced Systems. AIRCable USB Dongle BlueCats BlueSense Networks Estimote
An Introduction to Regular Expression with VBScript By Scott Mitchell Introduction: Let me start out by saying that I am no expert when it comes to regular expression! I have used regular expression on only a few occasions, and that was when writing some small Perl utilities for my Linux box. I am by no means an expert in the field. However, I've decided that I'd like to improve my regular expression skills, so I started studying up, and have decided to document my education in the form of articles to help others who are interested in learning regular expression! Regular Expression's Roots: Regular expression use to be a thing that only UNIX users knew about. No, I don't want to hear any excuses that sound like, "I don't have the VBScript 5 Engine, so I don't need to learn regular expression." So What the Heck is Regular Expression? Regular expression allows you to quickly search (and replace, if you like) for strings within another string. Character Matching: Character matching is the easiest, so let's start there. Pretty neat, eh?
Extending Paul Irish’s comprehensive DOM-ready execution | Viget Inspire Way back in March of '09, the intelligent (and dashing!) Paul Irish laid forth a markup-based means of executing JavaScript on page load. If you're unfamiliar with the technique, the basics are: Use class and id attributes on your document's body element that map to keys in an object literal. The method is noteworthy in that it enforces a sense of organization in both your JavaScript and your HTML. On a recent Ruby on Rails project, I iterated on Paul's method (dubbed the Garber-Irish Implementation by some), adding a touch of HTML5 and making use of some built-in Rails magic. The Garber-Irish Implementation First off, it'd be negligent to not mention that I'm a huge fan of HTML5's data-* attributes. <span data-lat="38.8951" data-lng="-77.0363"> 1600 Pennsylvania Ave. Taking a step back, we can use data-* attributes on the body element to provide an indication of where we are within an application: <body data-controller="<%= controller_name %>" data-action="<%= action_name %>">
REGEX - Introdução (10 votos, média 4.00 de 5) Detalhes Categoria: REGEX - Expressões Regulares Atualização: Terça, 21 Abril 2009 20:28 Autor: vovó Vicki Acessos: 7616 Uma expressão regular é um padrão que caracteriza uma certa porção de texto. O nome "expressão regular" vem de uma teoria matemática na qual este princípio de caracterização se baseia. Quem usa (ou deveria usar) expressões regulares? Todos os programadores que usam linguagens com suporte a expressões regulares, ou seja, que possuam "motores" de expressões regulares deveriam conhecer as ditas cujas. Para que servem as expressões regulares? Quando comecei a me interessar por este assunto, minha primeira dificuldade foi entender porque este troço foi inventado. Expressões Regulares servem para procurar e comparar CARACTERES. Pode parecer bobagem, mas as regex servem exatamente e tão somente para isto - possibilitam localizar CARACTERES e nada mais! Acontece que os textos possuem mais do que apenas letras e algarismos. Que vantagem Maria leva?
FS Gallery AURELIO.NET - Venha, leia com calma, aproveite a viagem