Skip to content

Instantly share code, notes, and snippets.

View arianacosta's full-sized avatar
📺
console logging

Arian Acosta arianacosta

📺
console logging
  • Miami, FL
  • 15:20 (UTC -04:00)
View GitHub Profile
@arianacosta
arianacosta / resize-swap.sh
Created March 2, 2017 13:34
Bash Script to Resize Swap File in Linux
#!/bin/bash
echo "====== Current Swap ======"
sudo swapon -s
echo "====== Turning Off Swap ======"
sudo swapoff /swapfile
echo "====== Allocating 4GB Swap ======"
sudo fallocate -l 4G /swapfile
echo "====== Making Swap ======"
sudo mkswap /swapfile
echo "====== Setting Permissions to Root Only ======"
@arianacosta
arianacosta / .bash_profile_custom
Last active March 16, 2019 15:14
Custom macOS Terminal
# Usage: Place this file in `~/.bash_profile_custom` and append 'source ~/.bash_profile_custom` to `~/.bash_profile`
# On macOS terminal, import the profile `solarized_dark_custom.terminal` and on the advanced tab, declare as `xterm-256color`
# For other terminals get the theme from: https://ethanschoonover.com/solarized/
#### Custom Prompt ####
# Customize ls output
alias ls='ls -Fh'
# Get last 2 directories
@arianacosta
arianacosta / bin.js
Last active May 17, 2019 18:17 — forked from zkat/index.js
npx is cool
#!/usr/bin/env node
console.log('this is bin!')
@arianacosta
arianacosta / InvokeGetGreetingLambda.ts
Last active October 18, 2019 22:33
Uses TS interfaces to create a request and get a response from Lambdas
import { Lambda } from 'aws-sdk'
import { GetGreetingRequest, GetGreetingResponse } from './GetGreetingLambda.ts';
(async () => {
const lambda = new Lambda({
apiVersion: '2015-03-31',
region: 'us-east-1',
});
@arianacosta
arianacosta / UserDto.ts
Created February 8, 2020 18:44
Data Transfer Object for the User type
export class UserDto {
static from(input: unknown) {
const parsedInput = typeof input === 'string' ? JSON.parse(input) : input;
if(!UserDto.isValid(parsedInput)) {
throw Error('Invalid input type');
}
// at this point `parsedInput` is guaranteed to match `UserDto`
const { firstName, lastName, isFormal } = parsedInput;
@arianacosta
arianacosta / InitiatorDtoLambda.ts
Last active February 8, 2020 18:48
Lambda that invokes another lambda with DTOs
import { Lambda } from 'aws-sdk';
import { UserDto } from './UserDto';
import { GreetingDto } from './GreetingDto';
const lambda = new Lambda({
apiVersion: '2015-03-31',
region: 'us-east-1',
});
export const handler = async (event: any) => {
@arianacosta
arianacosta / GreetingLambda.ts
Last active February 8, 2020 19:12
Lambda that receives a UserDto and returns a GreetingDto
import { UserDto } from './UserDto';
import { GreetingDto } from './GreetingDto';
export const handler = async (event: any): Promise<GreetingDto> => {
const userDto = UserDto.from(event);
// safely access user properties
const greeting = userDto.isFormal ?
`Dear ${userDto.firstName} ${userDto.lastName}, welcome back.` :
`Hey ${userDto.firstName} ${userDto.lastName}! Long time no see.`;
@arianacosta
arianacosta / GreetingDto.js
Created February 8, 2020 19:33
Similar to UserDto, but with other properties
export class GreetingDto {
static from(input: unknown) {
const parsedInput = typeof input === 'string' ? JSON.parse(input) : input;
if(!GreetingDto.isValid(parsedInput)) {
throw Error('Invalid input type');
}
const { greeting } = parsedInput;
export interface GetGreetingRequest {
firstName: string;
lastName: string;
isFormal: boolean;
}
export interface GetGreetingResponse {
greeting: string;
}
@arianacosta
arianacosta / print_style
Created July 15, 2017 19:31
Print colored text in a bash script
#!/bin/bash
# prints colored text
print_style () {
if [ "$2" == "info" ] ; then
COLOR="96m";
elif [ "$2" == "success" ] ; then
COLOR="92m";
elif [ "$2" == "warning" ] ; then