Skip to content

Instantly share code, notes, and snippets.

View andreasonny83's full-sized avatar
:octocat:
<Coding />

Andrea Z. andreasonny83

:octocat:
<Coding />
View GitHub Profile
@andreasonny83
andreasonny83 / script.sh
Created October 19, 2017 14:04
Rename *.dev.ts to .ts
#!/bin/bash
# Find and rename all the modules files according to the target environment
env=${1-"dev"}
dir="src/app/components"
find $dir -name "*.$env.ts" -type f | while read file
do
base=$(basename $file)
Array.prototype.mySum = function(callback) {
const vals = this;
const res = [];
for (var i = 0; i < vals.length; i++) {
res.push(callback(this[i]));
}
return res;
{
"name": "package-name",
"version": "0.0.0",
"description": "package-name short description",
"main": "lib/cli/index.js",
"bin": {
"package-name": "./bin/index.js"
},
"scripts": {
"test": "jest --watchAll"
@andreasonny83
andreasonny83 / handler.js
Last active September 17, 2018 08:11
sendMail
// Copyright (c) 2018 AndreaSonny <[email protected]> (https://github.com/andreasonny83)
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
'use strict';
const AWS = require('aws-sdk');
const ses = new AWS.SES();
@andreasonny83
andreasonny83 / conditiona- value.js
Last active March 19, 2019 12:09
Conditional Object key
// Conditional value
const a = {
...(someCondition && {b: 5})
}
// Remove key from object
const postData = {
token: 'secret-token',
publicKey: 'public is safe',
@andreasonny83
andreasonny83 / vim.md
Last active February 9, 2019 10:59
VIM

Convert to HEX

:%!xxd
@andreasonny83
andreasonny83 / class-singleton.js
Last active February 17, 2019 22:15
Singleton Pattern
/**
* The singleton pattern is a pattern used to restrict an object to a single instance.
* A singleton creates an instance of an object if that object does not exist.
* If it exists it returns the existing instance.
*/
class Car {
constructor(model, year, miles) {
if(Car.exists){
return Car.instance
@andreasonny83
andreasonny83 / class-factory.js
Last active February 17, 2019 22:13
Factory Pattern
/**
* The factory pattern abstracts object creation by providing an interface, where we can specify the type of
* factory object to be created.
*
* The Factory pattern can be especially useful when applied to the following situations:
*
* - When our object or component setup involves a high level of complexity,
* e.g. if it strongly depends on dynamic factors or application configuration.
* - When we need to easily generate different instances of objects depending on the environment we are in
* - When we're working with many small objects or components that share the same properties
@andreasonny83
andreasonny83 / class-facade.js
Created February 17, 2019 22:09
Facade pattern
/**
* The Facade pattern simplifies and hides the underlying complexity of a large abody of
* code by providing a cleaner and easy to use interface.
*/
class TaskService {
constructor(data){
this.name = data.name;
this.priority = data.priority;
this.project = data.project;
@andreasonny83
andreasonny83 / top.md
Last active January 21, 2020 12:58
Background processes

ps aux | grep node

run top find the process id (PID) ps -efl | grep 10399 kill -9 10399