Skip to content

Instantly share code, notes, and snippets.

View ahmadalfy's full-sized avatar

Ahmad Alfy ahmadalfy

View GitHub Profile
export function autoUnsubscribe(subscriptions: string[] = []) {
return (componentType) => {
const orgFactory = componentType.ngComponentDef.factory;
componentType.ngComponentDef.factory = (...args) => {
const component = orgFactory(...args);
componentType.ngComponentDef.onDestroy = () => {
if (component.ngOnDestroy) {
component.ngOnDestroy();
@benrobertsonio
benrobertsonio / lazy-video-loader.js
Last active November 4, 2019 22:02
Lazy Loading Video Based on Connection Speed
class LazyVideoLoader {
constructor() {
this.videos = [].slice.call(document.querySelectorAll('.hero__bgvideo'));
// Abort when:
// - The browser does not support Promises.
// - There no videos.
// - If the user prefers reduced motion.
// - Device is mobile.
if (
@tomhodgins
tomhodgins / rational.html
Last active August 26, 2020 21:08
Aspect-ratio polyfill using syntax `-eq-aspect-ratio: ;`
<h1>Aspect Ratio Polyfill</h1>
<h2>Demo</h2>
<div id=demo1>ratio alone</div>
<div id=demo2>width + ratio</div>
<div id=demo3>height + ratio</div>
<div id=demo4>width + height + ratio</div>
<div id=demo5>important means nothing</div>
<h2>Goal</h2>
@nerandell
nerandell / code-review-checklist.md
Last active November 15, 2024 11:25
PHP Code Review Guidelines

Make sure these boxes are checked before submitting/approving the PR

General

  • The code works
  • The code is easy to understand
  • Follows coding conventions
  • Names are simple and if possible short
  • Names are spelt correctly
  • Names contain units where applicable
  • There are no usages of magic numbers
@adamreisnz
adamreisnz / package.json
Last active August 22, 2024 10:12
Simple pure npm scripts build process
{
"name": "project-name",
"description": "Template for static sites",
"version": "1.0.0",
"homepage": "http://www.project-name.com",
"author": {
"name": "Adam Reis",
"url": "http://adam.reis.nz"
},
"license": "UNLICENSED",
@julianxhokaxhiu
julianxhokaxhiu / pagespeed_optimize_images.sh
Last active June 15, 2024 17:09
Recursively optimize all PNG and JPG files wherever they are from the script position and inner ( based on OPTING, PNGCRUSH, ADVANCECOMP and JPEGOPTIM )
#!/bin/bash
# Improved as per feedback from @pascal - https://gist.github.com/julianxhokaxhiu/c0a8e813eabf9d6d9873#gistcomment-3086462
find . -type f -iname "*.png" -exec optipng -nb -nc {} \;
find . -type f -iname "*.png" -exec advpng -z4 {} \;
find . -type f -iname "*.png" -exec pngcrush -rem gAMA -rem alla -rem cHRM -rem iCCP -rem sRGB -rem time -ow {} \;
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -exec jpegoptim -f --strip-all {} \;
anonymous
anonymous / Gruntfile.js
Created July 27, 2015 13:29
Sharing Configuration with Grunt
module.exports = function(grunt) {
require('./config.js')(grunt);
grunt.registerTask('default', ['concat', 'less', 'jshint', 'watch']);
};
@nodesocket
nodesocket / bootstrap.flatten.css
Last active April 1, 2021 23:37
Below are simple styles to "flatten" bootstrap. I didn't go through every control and widget that bootstrap offers, only what was required for https://commando.io, so your milage may vary.
/* Flatten das boostrap */
.well, .navbar-inner, .popover, .btn, .tooltip, input, select, textarea, pre, .progress, .modal, .add-on, .alert, .table-bordered, .nav>.active>a, .dropdown-menu, .tooltip-inner, .badge, .label, .img-polaroid {
-moz-box-shadow: none !important;
-webkit-box-shadow: none !important;
box-shadow: none !important;
-webkit-border-radius: 0px !important;
-moz-border-radius: 0px !important;
border-radius: 0px !important;
border-collapse: collapse !important;
background-image: none !important;
@passy
passy / jade.md
Last active August 17, 2020 09:35
Using Yeoman and Jade

Using Yeoman and Jade

Getting started

  • Make sure you have yo installed: npm install -g yo
  • Run: yo webapp
  • Install grunt-contrib-jade: npm install grunt-contrib-jade --save-dev

Customization