This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserEventsProcessor | |
include Shoryuken::Worker | |
shoryuken_options queue: 'User_Events.fifo', auto_delete: true | |
def perform(_sqs_event, payload) | |
Rails.logger.info("_sqs_event: #{_sqs_event}") | |
Rails.logger.info("UserEventsProcessor payload: #{payload}") | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Customer { | |
name: string | |
phone: string | |
} | |
declare function getCustomerData(id: string): Promise<Customer>; | |
declare function payCustomer(customer: Customer): void; | |
async function f() { | |
const customer = getCustomerData('c1') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isDate(input: unknown) : asserts input is Date { | |
if (input instanceof Date) | |
return; | |
else | |
throw new Error('Input must be a Date!'); | |
} | |
function getYear(input: unknown) : number { | |
isDate(input); | |
return input.getFullYear() // TypeScripts knows that input is Date |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isDate(input: unknown) { | |
if (input instanceof Date) | |
return; | |
else | |
throw new Error('Input must be a Date!'); | |
} | |
function getDayOfWeek(input: unknown) : number { | |
isDate(input); | |
return input.getFullYear() // TypeScript will fail compilation here! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Before | |
passPhrase = data.inputString || 'Unknown' //will not accept "" (empty string) | |
passCode = data.number || '-1111' // will not accept 0 | |
rememberMe = data.rememberFlag || true // will always be true!!! | |
// Now | |
passPhrase = data.inputString ?? 'Unknown' //Unknown only if inputString is not defined | |
passCode = data.number ?? '-1111' // 0 could be a passCode | |
rememberMe = data.rememberFlag ?? true // false is a valid value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prior to v3.7 | |
if (data && data.customer && data.customer.address) { | |
const {address} = data.customer | |
const fullAddress = `${address.street}, ${address.city}, ${address.state }${address.zipcode}` | |
} | |
// v3.7 onwards | |
// data access | |
const address = data?.customer?.address |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var array = [undefined, 'cat', false, 434, '', 32.0] | |
_.compact(array) | |
array.filter(Boolean) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var elements = [1,2,3,1,2,4,2,3,5,3] | |
_.uniq(elements) | |
[...new Set(elements)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,97] | |
_.includes(primes, 47) | |
primes.includes(79) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const elements = ["cat", "dog", "bat"] | |
_.some(elements, el => el.startsWith('c')) | |
elements.some(el => el.startsWith('c')) |