Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Vitor Carvalho lightningspirit

🏠
Working from home
View GitHub Profile
View shuffle.ts
function shuffle<T>(array: T[]): T[] {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
@lightningspirit
lightningspirit / react-lorem-ipsum.d.ts
Created Sep 14, 2020
Typescript typings for react-lorem-ipsum
View react-lorem-ipsum.d.ts
declare module "react-lorem-ipsum" {
import React from "react"
interface AvatarProps {
gender?: "all" | "male" | "female"
className?: string
width?: number
height?: number
alt?: string
}
@lightningspirit
lightningspirit / mu-passwords.php
Created Aug 25, 2020
Must-use WordPress plugin with a CLI command that resets passwords and generates a list of users with new passwords. It does not notify them. Plain simples user password reset mechanism that can be used for internal purposes.
View mu-passwords.php
<?php
/**
* Password management made easy
*
* @author Move Your Digital, Inc.
* @package Mu-Passwords
* @version 1.0.0
*/
/*
View rates_with_dollar_sign.csv
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 4.
country_code,country_name,category,price,prefixes,resource,direction,resolutions
AE,United Arab Emirates,,$0.27 ,9715,CALL,outbound,answered
AE,United Arab Emirates,,$0.27 ,971,CALL,outbound,answered
BR,Brazil,,$0.29 ,"551153, 551154, 551157, 55116, 55117, 55118, 55119, 55126, 55127, 55128, 55129, 55136, 55137, 55138, 55139, 55146, 55147, 55148, 55149, 55156, 55157, 55158, 55159, 55166, 55167, 55168, 55169, 55176, 55177, 55178, 55179, 55186, 55187, 55188, 55189, 5519, 55196, 55197, 55198, 55199, 55216, 55217, 55218, 55219, 55226, 55227, 55228, 55229, 55246, 55247, 55248, 55249, 55276, 55277, 55278, 55279, 55286, 55287, 55288, 55289, 55316, 55317, 55318, 55319, 55326, 55327, 55328, 55329, 5533, 55336, 55337, 55338, 55339, 55346, 55347, 55348, 55349, 55356, 55357, 55358, 55359, 55376, 55377, 55378, 55379, 55386, 55387, 55388, 55389, 55416, 55417, 55418, 55419, 55426, 55427, 55428, 55429, 55436, 55437, 55438, 55439, 55446, 55447, 55448, 55449, 55456, 55457, 55458, 55459, 55466, 55467, 55468, 55469, 55476, 55477,
View 2u_master_december_7th.csv
resource category country_code direction prefixes resolutions type price
CALL tollfree US inbound answered,missed,voicemail 0.012
CALL local US inbound answered,missed,voicemail 0.012
CALL US inbound answered,missed,voicemail 0.012
CALL tollfree AE inbound answered,missed,voicemail 0.67
CALL tollfree AR inbound answered,missed,voicemail 0.7
CALL local AR inbound answered,missed,voicemail 0.04
CALL local AT inbound answered,missed,voicemail 0.02
CALL tollfree AT inbound answered,missed,voicemail 0.59
CALL national AT inbound answered,missed,voicemail 0.04
@lightningspirit
lightningspirit / docker-prune-all
Last active Dec 4, 2018
Docker Container & Images Remover
View docker-prune-all
#!/usr/bin/env sh
docker rm $(docker ps -a | awk '{print $1}')
docker rmi $(docker images | awk '{print $3}')
@lightningspirit
lightningspirit / unload.js
Last active Nov 27, 2018
Redshift Unload query generator from SQL statement (warning: trusts input data)
View unload.js
#!/usr/bin/env node
const fs = require('fs')
const usage = () => {
console.log('Usage: unload <aws-arn> <sql-statement-filepath> <name-of-file-in-s3>')
}
if (process.argv.length < 5 || process.argv[2] == '-h') {
usage()
@lightningspirit
lightningspirit / add-cors.cj
Created Aug 2, 2018
This is a small portion of the core.cj file for call-timeline that aimed to add CORS support using two middlewares.
View add-cors.cj
(defn wrap-options
[app]
(fn [request]
(if (= (request :request-method) :options)
(into request {:status 204})
(app request))))
(defn add-header
[r name value]
(assoc-in r [:headers name] value))
@lightningspirit
lightningspirit / README.md
Created Feb 6, 2018
Hal representers lib prototype
View README.md

Hal representers for Elixir

Have JSON/Hal representers for your modules

Library idea

lib/hal/hal.ex:

defmodule APIWeb.Hal.Assignment
View taxidigital_inbound.csv
country_code type price
AR tollfree $0.70
AR local $0.04
AT local $0.02
AT national $0.04
AU tollfree $0.12
AU local $0.04
BA national $0.20
BB local $0.10
BE local $0.02