Skip to content

Instantly share code, notes, and snippets.

View Bengejd's full-sized avatar
🏠
Working from home

Jordan Benge Bengejd

🏠
Working from home
View GitHub Profile
@Bengejd
Bengejd / 1. autoplay-video.directive.ts
Last active April 30, 2020 16:51
Ionic - Auto play/pause videos on scroll.
import { Directive } from '@angular/core';
@Directive({
selector: 'video'
})
export class AutoplayVideoDirective { }
@Bengejd
Bengejd / 1. tab-bar.directive.ts
Last active October 31, 2018 03:36
Ionic 3 Show/Hide TabBar "directive" to programmatically hide/show tabs using this.tabs.show()/this.tabs.hide().
import {Directive} from '@angular/core';
/*
* This is technically a directive
* but we have to treat it like a provider to be able to manipulate it directly.
* So it must be imported into our app.module as a provider, instead of a directive.
*
* The reason I'm keeping it as a directive, instead of a service provider, is because it interacts with the DOM
* and not any data retrial / presentation, even though it's imported as one...weird I know.
*
@Bengejd
Bengejd / Remove_unsupported_archetypes.sh
Last active August 5, 2021 09:18
XCode - Build Phase Script - Remove unsupported archetypes ( simulator x86_64 & i386) from frameworks on build.
# This removes the unsupported archetypes from frameworks on the build phase.
echo "Target architectures: $ARCHS"
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
# Credits : Jason Horwitz, https://github.com/sekati
# Aashish Tamsya, aashish.tamsya@gmail.com
#
#
# BuildVersion.sh
# @desc Auto-increment the build number every time the project is run.
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases Tab
# 3. Select: Add Build Phase -> Add Run Script
@Bengejd
Bengejd / Auto_increment_version_number_on_export_archive.sh
Created November 5, 2018 17:18
Auto-increment the version number (only) when a project is archived for export.
# Credits : Jason Horwitz, https://github.com/sekati
# Aashish Tamsya, aashish.tamsya@gmail.com
#
#
# VersionNumberIncrement.sh
# @desc Auto-increment the version number (only) when a project is archived for export.
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases Tab
# 3. Select: Add Build Phase -> Add Run Script
@Bengejd
Bengejd / difference.ts
Created December 17, 2018 21:39
Deep Diff between two objects, using Lodash - Supports nested arrays.
getDiff() {
function changes(object, base) {
let arrayIndexCounter = 0;
return _.transform(object, function (result, value, key) {
if (!_.isEqual(value, base[key])) {
let resultKey = _.isArray(base) ? arrayIndexCounter++ : key;
result[resultKey] = (_.isObject(value) && _.isObject(base[key])) ? changes(value, base[key]) : value;
console.log("Result: " + JSON.stringify(result));
}
});
@Bengejd
Bengejd / getFiles.ts
Created December 31, 2018 18:21
Node.js recursively grab all files in folder
function getFiles(dir: string, fileList?: []) {
let files = fs.readdirSync(dir);
fileList = fileList || [];
files.forEach(async (file) => {
if(fs.statSync(dir + file).isDirectory()) {
// @ts-ignore
fileList = await getFiles(dir + file + '/', fileList);
} else {
// @ts-ignore
fileList.push( dir + '/' + file);
@Bengejd
Bengejd / lodash-sort-by-moment.ts
Last active February 6, 2019 12:09
A quick and simple way to order an array of objects that have a moment.js date property, using Lodash!
import * as _ from 'lodash';
...
/*
* Group them by the formatted date below.
* The more specific this format is, the smaller the groups will become.
*/
private groupMessagesByDate(messages) {
return _(messages)
.groupBy((m: any) => m.date.format('MM/DD/YYYY'))
@Bengejd
Bengejd / _aspect-ratio.scss
Last active February 10, 2019 20:50
Maintain aspect ratio in scss (height = width).
@mixin aspectRatio($ratio: '1:1', $width: 100%) {
width: $width;
@if($ratio == '1:1') {
padding-top: 100%; /* 1:1 Aspect Ratio */
}
@else if($ratio == '16:9') {
padding-top: 56.25%; /* 16:9 Aspect Ratio */
}
@else if($ratio == '4:3') {
padding-top: 75%; /* 4:3 Aspect Ratio */
@Bengejd
Bengejd / _scroll-in-textarea.scss
Created February 10, 2019 20:56
Ionic scroll in text-areas.
@mixin scrollInText() {
overflow: initial !important;
}