Skip to content

Instantly share code, notes, and snippets.

View nhducit's full-sized avatar
🚀

nhducit nhducit

🚀
View GitHub Profile

intellij javascript live templates

Just a dump of handy live templates I use with IntelliJ. They should also work with WebStorm.

How to

  • Go to settings.
  • Search for live templates.
  • Under the javascript section you should be able to manage your templates.
@nhducit
nhducit / Javascript Natural Sort Algorithm With Unicode Support
Last active January 20, 2022 04:06
Javascript Natural Sort Algorithm With Unicode Support
/*
* Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
* Author: Jim Palmer (based on chunking idea from Dave Koelle)
* Reference: http://www.overset.com/2008/09/01/javascript-natural-sort-algorithm/
*/
function naturalSort (a, b) {
var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
sre = /(^[ ]*|[ ]*$)/g,
dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
hre = /^0x[0-9a-f]+$/i,
//
// Regular Expression for URL validation
//
// Author: Diego Perini
// Updated: 2010/12/05
// License: MIT
//
// Copyright (c) 2010-2013 Diego Perini (http://www.iport.it)
//
// Permission is hereby granted, free of charge, to any person
@nhducit
nhducit / checkDuplicateID
Last active August 29, 2015 14:14
Javascript snippet to check duplicated ID in html page
Select all below snippet => drag and drop in browser bookmark bar
=> click on bookmark which you have just add => check the browser console
javascript:(function(){var e={};$("[id]").each(function(){var t=$('[id="'+this.id+'"]');if(t.length>1&&t[0]===this){e.id=this.id;e.obj=this;e.obj2=t[0]}});console.warn("Duplicate ID:",e.id,e.obj,e.obj2)})();
var myString = 'EXAMPLEstring';
var myNewString = myString.replace(/[A-Z]/g, '0');
console.log(myNewString);
function replaceFunc (a, b, c) {
console.log(a, b, c);
return a.toLowerCase();
}
var myOtherString = myString.replace(/[A-Z]/g, replaceFunc);
@nhducit
nhducit / introrx.md
Created October 2, 2015 03:22 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
http://ejohn.org/blog/javascript-array-remove/
@nhducit
nhducit / README.md
Created July 13, 2016 14:46 — forked from agnoster/README.md
My ZSH Theme

agnoster.zsh-theme

A ZSH theme optimized for people who use:

  • Solarized
  • Git
  • Unicode-compatible fonts and terminals (I use iTerm2 + Menlo)

For Mac users, I highly recommend iTerm 2 + Solarized Dark

export const GoogleApi = function(opts) {
opts = opts || {}
const apiKey = opts.apiKey;
const libraries = opts.libraries || [];
const client = opts.client;
const URL = 'https://maps.googleapis.com/maps/api/js';
const googleVersion = '3.22';
let script = null;
@nhducit
nhducit / Child.js
Created August 27, 2016 03:00 — forked from eyesofkids/Child.js
Simple React Lifecycle methods test
import React from 'react'
var Child = React.createClass({
getInitialState: function(){
console.log('Child getInitialState');
return { value: 'start'}
},
getDefaultProps: function(){
console.log('Child getDefaultProps');