Skip to content

Instantly share code, notes, and snippets.

nhducit nhducit

  • Ho Chi Minh
Block or report user

Report or block nhducit

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
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 / Javascript Natural Sort Algorithm With Unicode Support
Last active Aug 29, 2015
Javascript Natural Sort Algorithm With Unicode Support
View 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:
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,
EpokK / scrollDown.js
Last active Dec 27, 2015
scroll to bottom of div
View scrollDown.js
window.onload = function () {
var objDiv = document.getElementById("idOfYourDiv");
objDiv.scrollTop = objDiv.scrollHeight;
EpokK / clickToEdit.js
Last active Dec 28, 2015
clickToEdit directive with AngularJS
View clickToEdit.js
app.directive("clickToEdit", function() {
var editorTemplate = '<div class="click-to-edit">' +
'<div ng-hide="view.editorEnabled">' +
'{{value}} ' +
'<a ng-click="enableEditor()">Edit</a>' +
'</div>' +
'<div ng-show="view.editorEnabled">' +
'<input ng-model="view.editableValue">' +
'<a href="#" ng-click="save()">Save</a>' +
' or ' +
blaryjp / ng-dt
Created Jan 21, 2014
Angular directive for Bootstrap3 datetimepicker -
View ng-dt
directive('dt', function(){
return {
require: '?ngModel',
restrict: 'A',
link: function ($scope, element, attrs, controller) {
var updateModel, onblur;
if (controller !== null) {
eabait /
Last active Jul 13, 2017
Charting Libraries
AllThingsSmitty / replace.js
Last active Jul 22, 2017
Using String.replace() with regular expressions
View replace.js
var myString = 'EXAMPLEstring';
var myNewString = myString.replace(/[A-Z]/g, '0');
function replaceFunc (a, b, c) {
console.log(a, b, c);
return a.toLowerCase();
var myOtherString = myString.replace(/[A-Z]/g, replaceFunc);

Type Safe JSON Decoding in Elm

The power of a Static Typed language can seem magical at first. But the goal here is to take a tiny peak behind that curtain.

Elm's implementation of JSON parsing is type safe and how it achieves that can seem like a mystery. Even though I got the code to work, it took me a while to fully understand how it works.

I'm writing it down here for 2 reasons. To help others gain a greater understanding of Types and so I don't forget what I learned.

Word of Caution

View form.js
import React from 'react'
import revalidation from 'revalidation'
import gql from 'graphql-tag.macro'
import { filter } from 'graphql-anywhere'
import { curry } from 'ramda'
import { compose, withProps, withHandlers } from 'recompose'
import { graphql } from 'react-apollo'
import { Button } from '../common/styled'
import { getValue } from '../form/utils'
import { isRequired } from '../../utils/validation'
You can’t perform that action at this time.