[JS] Fastest way for searching a monodimensional array?
var myAr = ['apple', 5, 6];
if(String('^' + myAr.join('^')).indexOf("^5") != -1)
console.log("found!");
else
console.log("not found :(");
About
Hi, I'm Christian Castelli, a 28 years old italian programmer located in Pisa (Italy). Here I post small snippets of code which can be useful in my work.Links
Codepuzzling main siteMy Life Style
while(passion) {
try {
myLife.run();
}catch(LifeExceptions) {
stronger++;
continue;
}
}
Following
var myAr = ['apple', 5, 6];
if(String('^' + myAr.join('^')).indexOf("^5") != -1)
console.log("found!");
else
console.log("not found :(");
I’ve taken this little piece of code around the Web (sorry, I forgot the original source) and it’s a good example on how to develop a plugin for jQuery:
/** Usage:
* $.random(int);
* $.randomBetween(min, max); */
jQuery.extend({
random: function(X) {
return Math.floor(X * (Math.random() % 1));
},
randomBetween: function(MinV, MaxV) {
return MinV + jQuery.random(MaxV - MinV + 1);
}
});
user@host:~$ sudo updatedb user@host:~$ locate arch_fglrx_2.6.34.patch /usr/src/fglrx-8.732/patches/arch_fglrx_2.6.34.patch /var/lib/dkms/fglrx/8.732/build/patches/arch_fglrx_2.6.34.patch # substitute first two lines of each file with these lines (without #) # --- a/kcl_wait.c 2010-04-13 20:02:46.494496561 +0200 # +++ b/kcl_wait.c 2010-04-13 19:52:00.054563389 +0200 user@host:~$ sudo vim /usr/src/fglrx-8.732/patches/arch_fglrx_2.6.34.patch user@host:~$ sudo vim /var/lib/dkms/fglrx/8.732/build/patches/arch_fglrx_2.6.34.patch user@host:~$ sudo apt-get --no-download install fglrx fglrx-amdcccleVia: Ubuntu forums
Here it is a small view to see all triggers stored in the DBMS. IMHO it’s more usable than going into INFORMATION_SCHEMA database and browse TRIGGERS records.
CREATE VIEW `List_triggers` AS
SELECT `TRIGGER_NAME` AS `Name`, `TRIGGER_SCHEMA` AS `Database`,
`EVENT_OBJECT_TABLE` AS `Table`,
CONCAT_WS(" ", ACTION_TIMING, EVENT_MANIPULATION) AS `Action`
FROM `INFORMATION_SCHEMA`.`TRIGGERS`
When you’re without words…a facepalm says it all
As simple as:
gconftool-2 --shutdown rm -rf ~/.gconf/apps/panel pkill gnome-panelIf you want to restore, in example, Games menu from Applications, you have to:
cd ~/.config/menus vim applications.menuand then remove (in my case) Deleted node:
<Menu>
<Name>Games</Name>
<Exclude>
<Filename>mahjongg.desktop</Filename>
</Exclude>
<AppDir>/home/chris/.local/share/applications</AppDir>
<!-- remove this node </Deleted> -->
</Menu>
Via Ubuntu forums here and here.
I was disappointed when I figured out that Vuze didn’t work anymore after having upgraded to Lucid Lynx. So I launched the program in the shell and I discovered it couldn’t find some Swing stuff for creating the GUI. Back to Java Sun 6, so:
chris@sirio:~$ sudo update-java-alternatives -l java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk java-6-sun 63 /usr/lib/jvm/java-6-sun chris@sirio:~$ sudo update-java-alternatives -s java-6-sun
The development release of Chrome allow to install extension as for Firefox, but the process of installation (and even of creation as I heard from some developers) is faster. Here it is my list:
function isValidEmail($email)
{
if(version_compare(PHP_VERSION, '5.2.0', '>=')
return filter_var($email, FILTER_VALIDATE_EMAIL);
else
return eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$', $email);
}
Regular expressions are a very powerful weapon for the developer if he can deals with all the pain of testing, debugging and learning the quirks of this matter. I’m collecting some links to be red one day, when I’ll got time to dive more deeply in the argument:
java.util.regex. If you’re looking for regex testing targeting java, take a look at Regular Expression Test Applet;