Skip to content

Instantly share code, notes, and snippets.

View MoatazAbdAlmageed's full-sized avatar
⌨️
pressing f12 key

Moataz Mohammady MoatazAbdAlmageed

⌨️
pressing f12 key
View GitHub Profile
@zcaceres
zcaceres / Revealing-Module-Pattern.md
Last active May 4, 2024 06:44
Using the Revealing Module Pattern in Javascript

The Revealing Module Pattern in Javascript

Zach Caceres

Javascript does not have the typical 'private' and 'public' specifiers of more traditional object oriented languages like C# or Java. However, you can achieve the same effect through the clever application of Javascript's function-level scoping. The Revealing Module pattern is a design pattern for Javascript applications that elegantly solves this problem.

The central principle of the Revealing Module pattern is that all functionality and variables should be hidden unless deliberately exposed.

Let's imagine we have a music application where a musicPlayer.js file handles much of our user's experience. We need to access some methods, but shouldn't be able to mess with other methods or variables.

Using Function Scope to Create Public and Private Methods

@mbeaudru
mbeaudru / Checkbox.js
Created March 22, 2017 09:06
Checkbox with styled-components
import React, { Component, PropTypes } from 'react';
import styled from 'styled-components';
class Checkbox extends Component {
render() {
return (
<Styled
onClick={() => this.props.onChange(!this.props.checked)}
>
<input
@mentos1386
mentos1386 / Webstorm-Airbnb-Javascript-codeStyle.xml
Created March 12, 2017 11:03
Airbnb inspired Webstorm Javascript CodeStyle
<code_scheme name="Airbnb">
<option name="RIGHT_MARGIN" value="100" />
<option name="HTML_ATTRIBUTE_WRAP" value="4" />
<option name="HTML_ELEMENTS_TO_INSERT_NEW_LINE_BEFORE" value="" />
<option name="HTML_ENFORCE_QUOTES" value="true" />
<DBN-PSQL>
<case-options enabled="false">
<option name="KEYWORD_CASE" value="lower" />
<option name="FUNCTION_CASE" value="lower" />
<option name="PARAMETER_CASE" value="lower" />
@scottopolis
scottopolis / splice-object-array.js
Last active January 31, 2023 06:54
Remove object from array of objects in Javascript
// we have an array of objects, we want to remove one object using only the id property
const apps = [{id:34,name:'My App',another:'thing'},{id:37,name:'My New App',another:'things'}];
// get index of object with id of 37
const removeIndex = apps.findIndex( item => item.id === 37 );
// remove object
apps.splice( removeIndex, 1 );
@shaikotahmed19
shaikotahmed19 / Owl carousel 1
Last active June 5, 2021 18:09
Owl Carousel 1
@veggiemonk
veggiemonk / .gitconfig
Last active June 4, 2024 08:23
simple zshrc config file with Oh-My-ZSH
[user]
name = Julien Bisconti
email = ******
[core]
excludesfile = ~/.gitignore
pager = diff-so-fancy | less --tabs=1,5 -R
editor = /usr/bin/vim
[alias]
wow = log --all --graph --decorate --oneline --simplify-by-decoration
@vibhavsinha
vibhavsinha / vdocipherNode.js
Created December 7, 2016 13:24
sample code to generate OTP on nodejs
/// this is the backend code. Use the generated OTP in this file to embed videos using embed code as given on
/// https://www.vdocipher.com/page/api.curl
let request = require('request');
var api_url = "https://api.vdocipher.com/v2/";
var secret_key = "API_SECRET_KEY";
function getOtp(v, c) {
request.post({
@dieterrosch
dieterrosch / backup_all_docker_images.sh
Last active August 11, 2023 19:48
A bash script to backup all docker images to files
#!/usr/bin/sh
if [[ $# -eq 0 ]]; then
echo "Usage: $0 <backup_dir>"
exit
fi
destination=$1
if ! type "pv" > /dev/null; then
echo 'pv' command not found on your system, install it to get a nice progress indicator...
else
@broofa
broofa / pre-commit
Last active February 23, 2024 08:55
Git pre-commit hook that runs `eslint` with the `--fix` option to fix up issues where possible, and adds "fix"ed files into the commit
#!/bin/bash
cd "$(git rev-parse --show-toplevel)"
ESLINT="node_modules/.bin/eslint"
pwd
if [[ ! -x "$ESLINT" ]]; then
printf "\t\033[41mPlease install ESlint\033[0m (npm install eslint)\n"
exit 1
fi
@iamravenous
iamravenous / _mediaqueries.scss
Created September 21, 2016 19:50
Sass mobile-first media queries mixins
/*
* Sass mobile-first media queries mixins
* @author Franco Moya - @iamravenous
*/
/* Breakpoints list map based on Bootstrap 4 grid */
$breakpoints: (
xs: 0,
sm: 544px,