Skip to content

Instantly share code, notes, and snippets.

View behnamazimi's full-sized avatar

Behnam behnamazimi

View GitHub Profile
@Alex1990
Alex1990 / safeActiveElement.js
Last active December 20, 2019 09:54
Get the current active element safely.
/**
* Get the current active element safely.
* Ref: https://github.com/jquery/jquery-ui/blob/2b84531ae9331f60e4d739fabca6d78abde89ae1/ui/safe-active-element.js
*/
function safeActiveElement(doc) {
doc = doc || document;
var activeElement;
// Support: IE 9 only
// IE9 throws an "Unspecified error" accessing document.activeElement from an <iframe>
@nimahkh
nimahkh / App.css
Last active July 10, 2020 03:05
reactjs simple context functions to manage states
.App {
text-align: center;
}
.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 40vmin;
pointer-events: none;
}
const recordAudio = () => {
return new Promise(resolve => {
navigator.mediaDevices.getUserMedia({ audio: true })
.then(stream => {
const mediaRecorder = new MediaRecorder(stream);
const audioChunks = [];
mediaRecorder.addEventListener("dataavailable", event => {
audioChunks.push(event.data);
});
@bluehazetech
bluehazetech / css-media-queries
Created February 6, 2014 17:14
CSS: SCSS Breakpoints, Mixins and Usage
/*------------------------------------*\
breakpoint vars
\*------------------------------------*/
$break-320: 20em;
$break-321: 20.0625em;
$break-480: 30em;
$break-600: 37.5em;
$break-768: 48em;
$break-980: 61.25em;
$break-1024: 64em;
function partition(inputArray, callback) {
const result = {};
for (const [indexOfValue, value] of inputArray.entries()) {
const propertyKey = callback(value, indexOfValue);
if (propertyKey === null || propertyKey === '') {
continue;
}
if (!{}.hasOwnProperty.call(result, propertyKey)) {
result[propertyKey] = [];
}
@getify
getify / naf.js
Created June 27, 2012 14:19
requestNextAnimationFrame() and cancelNextAnimationFrame()
// requires raf.js (polyfil)
(function(){
var ids = {};
function requestId(){
var id;
do {
id = Math.floor(Math.random() * 1E9);
} while (id in ids);
@5t3ph
5t3ph / element-classes-and-ids-vanilla.css
Last active January 25, 2022 04:06
Tag HTML elements with their class names and IDs to visualize page structure
*[class],
*[id] {
position: relative;
outline: 2px dashed red;
}
*[class]::before, *[class]::after,
*[id]::before,
*[id]::after {
position: absolute;
@cvan
cvan / webgl-detect-gpu.js
Last active January 19, 2024 02:54
use JavaScript to detect GPU used from within your browser
var canvas = document.createElement('canvas');
var gl;
var debugInfo;
var vendor;
var renderer;
try {
gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
} catch (e) {
}
@broofa
broofa / checkForUndefinedCSSClasses.js
Last active January 21, 2024 17:22
ES module for detecting undefined CSS classes (uses mutation observer to monitor DOM changes). `console.warn()`s undefined classes.
/**
* Sets up a DOM MutationObserver that watches for elements using undefined CSS
* class names. Performance should be pretty good, but it's probably best to
* avoid using this in production.
*
* Usage:
*
* import cssCheck from './checkForUndefinedCSSClasses.js'
*
* // Call before DOM renders (e.g. in <HEAD> or prior to React.render())
@paulsturgess
paulsturgess / service.js
Last active February 2, 2024 17:24
An example Service class wrapper for Axios
import axios from 'axios';
class Service {
constructor() {
let service = axios.create({
headers: {csrf: 'token'}
});
service.interceptors.response.use(this.handleSuccess, this.handleError);
this.service = service;
}