function _buildHash(value) {
var hash = 0, i, currChr;
if (value.length === 0) { return hash; }
for (i = 0; i < value.length; i++) {
currChr = value.charCodeAt(i);
hash = ((hash << 5) - hash) + currChr; // jshint ignore:line
hash |= 0; // jshint ignore:line
}
return hash.toString(2);
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Print styles */ | |
| body { | |
| width:100% !important; | |
| margin:0 !important; | |
| padding:0 !important; | |
| line-height: 1.45; | |
| font-family: Garamond,"Times New Roman", serif; | |
| color: #000; | |
| background: none; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ctrl.reload = function() { | |
| return $state.transitionTo($state.current, $stateParams, { | |
| reload: true | |
| }).then(function() { | |
| $ctrl.hideContent = true; | |
| return $timeout(function() { | |
| return $ctrl.hideContent = false; | |
| }, 1); | |
| }); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // with print | |
| $object = new MyObject(); | |
| // second param true make return value instead of print | |
| error_log( print_r( $object, true ) ); | |
| // with var_dump | |
| function write_error_log( $object = null ){ |
All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.
elem.offsetLeft,elem.offsetTop,elem.offsetWidth,elem.offsetHeight,elem.offsetParentelem.clientLeft,elem.clientTop,elem.clientWidth,elem.clientHeightelem.getClientRects(),elem.getBoundingClientRect()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Return a timestamp with the format "m/d/yy h:MM:ss TT" | |
| * @type {Date} | |
| */ | |
| function timeStamp() { | |
| // Create a date object with the current time | |
| var now = new Date(); | |
| // Create an array with the current month, day and time |
How to start any new Node.js project:
$ npx license mit > LICENSE
$ npx gitignore node
$ npx covgen YOUR_EMAIL_ADDRESS
$ npm init -y
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ng-enter="myFunction()" | |
| app.directive('ngEnter', function () { | |
| return function (scope, element, attrs) { | |
| element.bind("keydown keypress", function (event) { | |
| if(event.which === 13) { | |
| scope.$apply(function (){ | |
| scope.$eval(attrs.ngEnter); | |
| }); | |
| event.preventDefault(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // from: https://repl.it/@dericgw/ReduxRecreated | |
| // There area lot more checks in the Redux lib but this gets the point across. | |
| function createStore(reducer, initialState) { | |
| let currentState = initialState; | |
| const listeners = []; | |
| const getState = () => currentState; | |
| function subscribe(listener) { | |
| listeners.push(listener); |