Skip to content

Instantly share code, notes, and snippets.

View jherax's full-sized avatar
👾
Performance focused

David Rivera jherax

👾
Performance focused
View GitHub Profile
@koistya
koistya / App.js
Last active June 8, 2022 09:55
How to add `onscroll` event in ReactJS component
import React from 'react';
let lastScrollY = 0;
let ticking = false;
class App extends React.Component {
componentDidMount() {
window.addEventListener('scroll', this.handleScroll, true);
}
@jherax
jherax / sortBy.js
Last active May 31, 2021 07:50
Sorts an array with multiple ordering criteria (Schwartzian transform)
/**
* Sorts an array and allows multiple sorting criteria.
*
* It applies the Schwartzian transform:
* https://en.wikipedia.org/wiki/Schwartzian_transform
*
* Author: David Rivera
* Github: https://github.com/jherax
*
* You can fork this project on github:
@Antaris
Antaris / Disposable.js
Last active February 6, 2021 19:47
A C#-like dispose pattern implemented in javascript - with underscorejs and qunit. Testable: http://jsfiddle.net/52CnZ/14/
!function(root, _, undefined) {
var Disposable = root.Disposable = function() {
this.disposed = false;
};
Disposable.prototype = {
_dispose: function() {
if (!this.disposed) {
this.dispose();
this.disposed = true;
/**
* range()
*
* Returns an array of numbers between a start number and an end number incremented
* sequentially by a fixed number(step), beginning with either the start number or
* the end number depending on which is greater.
*
* @param {number} start (Required: The start number.)
* @param {number} end (Required: The end number. If end is less than start,
* then the range begins with end instead of start and decrements instead of increment.)
@jherax
jherax / clone.js
Last active May 30, 2020 15:42
Clones or extends an object (deep copy) supporting objects with circular references
/**
* @author
* David Rivera (jherax)
* https://github.com/jherax
*/
/* eslint-disable no-bitwise */
/** @private */
const toString = Object.prototype.toString;
@jherax
jherax / fromOneLevelDepth.js
Last active May 30, 2020 15:41
Build a one-level-depth object, by moving all nested objects to the first level
// @private
var isObject = (value) =>
value != null && typeof value === 'object';
/**
* @private
* Restores the one-level-depth object to the original nested object.
*
* @param {Array} names: list of keys in the object
* @param {any} value: the value of the object to transform
@cmalard
cmalard / subl
Last active February 13, 2019 20:23 — forked from versedi/.sh
Cygwin + Sublime Text 3 : works with files and Git
#!/bin/bash
# To create in [.babun/]cygwin/usr/local/bin/subl with chmod +x
ARGS=""
while test $# -gt 0
do
ARGS="$ARGS ${1#/cygdrive/[a-zA-Z]}"; # Remove /cygdrive and disk letter from the path
shift
done
@gmilby
gmilby / createUUID.js
Created September 18, 2013 16:46
angular - create unique id
angular
.module('uuidApp', ['lvl.services'])
.controller('uuidCtl', ['$scope', 'uuid', function($scope, uuid){
$scope.generateUuid = function() {
$scope.new = uuid.new();
$scope.nInfo = new Date();
};
$scope.showEmpty = function() {
$scope.empty = uuid.empty();
@bennadel
bennadel / http-interpolation.htm
Created April 22, 2014 12:55
Using URL Interpolation With $http In AngularJS
<!doctype html>
<html ng-app="Demo">
<head>
<meta charset="utf-8" />
<title>
Using URL Interpolation With $http In AngularJS
</title>
</head>