Skip to content

Instantly share code, notes, and snippets.

View nhducit's full-sized avatar
🚀

nhducit nhducit

🚀
View GitHub Profile
//
// Regular Expression for URL validation
//
// Author: Diego Perini
// Created: 2010/12/05
// Updated: 2018/09/12
// License: MIT
//
// Copyright (c) 2010-2018 Diego Perini (http://www.iport.it)
//
@paulirish
paulirish / rAF.js
Last active March 22, 2024 00:00
requestAnimationFrame polyfill
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
@jboner
jboner / latency.txt
Last active May 23, 2024 06:51
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@agnoster
agnoster / README.md
Last active April 6, 2024 22:35
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

@puzrin
puzrin / Makefile
Last active May 13, 2023 07:17
Makefile example for fontello.com API
# Edit here - set path to you directory with config.json & fonts
FONT_DIR ?= ./assets/vendor/fontello/src
### Don't edit below ###
FONTELLO_HOST ?= https://fontello.com
fontopen:
@if test ! `which curl` ; then \
@eddiemoore
eddiemoore / nric-validation.js
Last active October 17, 2022 05:39
Validation for Singapore NRIC and FIN number
//Based on http://www.samliew.com/icval/
function validateNRIC(str) {
if (str.length != 9)
return false;
str = str.toUpperCase();
var i,
icArray = [];
for(i = 0; i < 9; i++) {
@EpokK
EpokK / scrollDown.js
Last active December 27, 2015 16:19
scroll to bottom of div
window.onload = function () {
var objDiv = document.getElementById("idOfYourDiv");
objDiv.scrollTop = objDiv.scrollHeight;
}
@EpokK
EpokK / clickToEdit.js
Last active December 28, 2015 08:09
clickToEdit directive with AngularJS
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 ' +
@branneman
branneman / better-nodejs-require-paths.md
Last active April 27, 2024 04:16
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@blaryjp
blaryjp / ng-dt
Created January 21, 2014 21:18
Angular directive for Bootstrap3 datetimepicker - http://eonasdan.github.io/bootstrap-datetimepicker/
angular.module('angularApp').
directive('dt', function(){
return {
require: '?ngModel',
restrict: 'A',
link: function ($scope, element, attrs, controller) {
var updateModel, onblur;
if (controller !== null) {