Skip to content

Instantly share code, notes, and snippets.

View eliashussary's full-sized avatar
🍊

Elias Hussary eliashussary

🍊
  • Toronto, Canada
  • 02:48 (UTC -05:00)
View GitHub Profile
@eliashussary
eliashussary / lettersToPhoneNumber.js
Last active February 22, 2017 13:59
A function to convert letters into a phone number sequence.
/**
* A function to convert letters into a phone number sequence.
* @param {string} searchStr - String of letters to convert into a phone number sequence.
* @returns {number} The String of letters converted into phone number sequence.
*/
function lettersToPhoneNumber(searchStr) {
// convert lowercase string to uppercase since we compare against uppercase;
// then split string into an array of letters;
searchStr = searchStr.toUpperCase().split('')
@eliashussary
eliashussary / Node Digital Ocean Spaces.js
Last active October 16, 2024 02:42
How to use Digital Ocean Spaces API with NodeJS using the AWS-SDK
import AWS from 'aws-sdk'
import Buffer from 'buffer'
AWS.config.setPromisesDependency(require('bluebird'))
;(async () => {
const spaces = new AWS.S3({
// {region}.digitaloceanspaces.com ex: nyc3.digitaloceanspaces.com
@eliashussary
eliashussary / ps-rename-files.ps1
Created February 6, 2018 16:03
Rename files from powershell cli.
dir | rename-item -NewName {$_.name -replace " ","_"}
@eliashussary
eliashussary / fillBlanks.js
Created February 13, 2018 16:33
fillBlanks takes an array with falsy/null values, and fills them with the previous value in the array. If null values appear without a previous value, you can use nullReplace to autofill it.
/**
* fillBlanks takes an array with falsy/null values, and fills them with the previous value in the array.
* If null values appear without a previous value, you can use nullReplace to autofill it.
* @example
* const arr = ["", "", 0, "", "", 1, "", 2, "", "", "", "Test", ""]
* fillBlanks(arr)
* // => [ null, null, 0, 0, 0, 1, 1, 2, 2, 2, 2, 'Test', 'Test' ]
* @example
* const arr = ["", "", 0, "", "", 1, "", 2, "", "", "", "Test", ""]
* fillBlanks(arr, "replaced")
@eliashussary
eliashussary / change-wallpaper.bat
Created February 16, 2018 15:35
A simple batch script to change your windows wallpaper. It takes a single argument, the path of your desired wallpaper.
echo off
:: Handle CLI Args
IF [%1]==[] (
echo No wallpaper path provided, please provide a full qualified path. Ex: C:\dir1\dir2\wallpaper.jpg
exit /b 1
)
:: Commands
echo Changing wallpaper to: %1
@eliashussary
eliashussary / psql-json-add-remove.sql
Last active March 19, 2018 15:45
Postgres Example of adding and removing keys from json
update "listingSubscriptions"
set criteria = (jsonb_set(criteria::jsonb, '{moveInDateParsed}', '["",""]'));
update "listingSubscriptions"
set "criteria" = (criteria::jsonb - 'moveInDate')::json;
update "listingSubscriptions"
set criteria = (jsonb_set(criteria::jsonb, '{listPrice}', to_jsonb('{0,6000}'::int[])))
where (criteria->'listPrice')::jsonb = '["",""]';
insert into "uiEvents"
select
row_number() over (order by id) + (select coalesce(max(id),0) from "uiEvents") as "id",
id as "userId",
tmp."eventTypes" as "eventType",
"createdAt",
"updatedAt"
from
users,
(select unnest(ARRAY['ONBOARD_MODAL','ONBOARD_SEARCH_TOUR']) as "eventTypes") as tmp
// paste in chrome console.
let answers = Array.prototype.slice
.call(
document.querySelectorAll(
"table > tbody > tr > td > table > tbody > tr > td:nth-child(2)[valign='top'] > div > span.correctAnswerFlag"
)
)
.reduce((acc, n) => {
const node = n.parentNode.children[2]
@eliashussary
eliashussary / 1-Store.js
Last active June 27, 2018 20:21
A proof of concept for a simple React state management tool using the Context API.
/**
* Title: Simple React State Management with Context
* Description:
* This is a React State Management proof of concept which uses the React ^16 Context API.
* This POC is loosely based on redux, with the ommission of reducers to limit the amount of boilerplate required.
*
* ---
* Author: Elias Hussary <[email protected]>
* Created: 2018-06-07
* Updated: 2018-06-07
@eliashussary
eliashussary / camelCase to snake_case postgres.sql
Created August 19, 2018 15:41
Script to generate alter statements for renaming table columns from camelCase to snake_case.
WITH from_table AS (
SELECT unnest(array[
-- tables go here
-- start
'bookSessions',
'bookTimeslots',
'bookUnits',
'carts',
'errorLogs',