Skip to content

Instantly share code, notes, and snippets.

View mhdSid's full-sized avatar
🔬
Innovating

moeSidani mhdSid

🔬
Innovating
  • Rakuten
  • Tokyo
View GitHub Profile
@mhdSid
mhdSid / arrayIterator.ts
Last active November 11, 2018 22:33
Simple & Generic Way to Iterate Backwards & Forwards through an Array
public iterateBackwards (arrayLength: number, index: number): number {
return index = (index <= 0) ? arrayLength - 1 : --index, index;
}
public iterateForwards (arrayLength: number, index: number): number {
return index = (index >= arrayLength - 1) ? 0 : ++index, index;
}
/*
* Usage
@edysegura
edysegura / angularjs-interceptor.js
Last active May 12, 2023 15:37 — forked from gnomeontherun/angularjs-interceptor.js
[angularjs] How to create an AngularJS HTTP Interceptor
// Intercepting HTTP calls with AngularJS.
angular.module('MyApp', [])
.config(function ($provide, $httpProvider) {
// Intercept http calls.
$provide.factory('MyHttpInterceptor', function ($q) {
return {
// On request success
request: function (config) {
// console.log(config); // Contains the data about the request before it is sent.
function hostReachable() {
// Handle IE and more capable browsers
var xhr = new ( window.ActiveXObject || XMLHttpRequest )( "Microsoft.XMLHTTP" );
var status;
// Open new request as a HEAD to the root hostname with a random param to bust the cache
xhr.open( "HEAD", "//" + window.location.hostname + "/?rand=" + Math.floor((1 + Math.random()) * 0x10000), false );
// Issue request and handle response
@gre
gre / easing.js
Last active April 30, 2024 04:58
Simple Easing Functions in Javascript - see https://github.com/gre/bezier-easing
/*
* This work is free. You can redistribute it and/or modify it under the
* terms of the Do What The Fuck You Want To Public License, Version 2,
* as published by Sam Hocevar. See the COPYING file for more details.
*/
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {