Skip to content

Instantly share code, notes, and snippets.

View auxcoder's full-sized avatar
🗼
Working from home

AuxCoder auxcoder

🗼
Working from home
View GitHub Profile
@auxcoder
auxcoder / build-hash.md
Created August 7, 2017 13:14
Generate hash from string, Javascript
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);
@auxcoder
auxcoder / typescript_angular.adoc
Created August 10, 2017 03:59 — forked from esfand/typescript_angular.adoc
AngularJS with TypeScript
@auxcoder
auxcoder / print.css
Created November 4, 2017 16:37
Set of print styles
/* 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;
@auxcoder
auxcoder / reload.js
Created January 18, 2018 14:39
Reload current State one time (angular, ui-router)
$ctrl.reload = function() {
return $state.transitionTo($state.current, $stateParams, {
reload: true
}).then(function() {
$ctrl.hideContent = true;
return $timeout(function() {
return $ctrl.hideContent = false;
}, 1);
});
};
@auxcoder
auxcoder / write-to-error-log.php
Created May 10, 2018 13:30
Writing to error_log with var_dump & print_r
<?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 ){
@auxcoder
auxcoder / what-forces-layout.md
Created August 24, 2018 00:45 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

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.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@auxcoder
auxcoder / timestamp.js
Created February 28, 2019 14:38 — forked from hurjas/timestamp.js
Print out a nicely formatted timestamp in JavaScript.
/**
* 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
@auxcoder
auxcoder / start-node-project.md
Created May 28, 2019 13:22
How to start a NodeJS project

How to start any new Node.js project:

$ npx license mit > LICENSE
$ npx gitignore node
$ npx covgen YOUR_EMAIL_ADDRESS
$ npm init -y
@auxcoder
auxcoder / ng-enter.js
Last active August 13, 2019 16:36
Simple directive, ng-enter, to invoke a function on hit the enter key.
// 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();
@auxcoder
auxcoder / redux-recreated.js
Last active January 30, 2020 15:11
A simple recreation of Redux
// 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);