Skip to content

Instantly share code, notes, and snippets.

View eliashussary's full-sized avatar
🍊

Elias Hussary eliashussary

🍊
  • Toronto, Canada
  • 05:36 (UTC -04:00)
View GitHub Profile
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
@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 = '["",""]';
@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 / 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 / ps-rename-files.ps1
Created February 6, 2018 16:03
Rename files from powershell cli.
dir | rename-item -NewName {$_.name -replace " ","_"}
@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 / 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('')