Skip to content

Instantly share code, notes, and snippets.

View shayan-ys's full-sized avatar

Shayan shayan-ys

View GitHub Profile
@shayan-ys
shayan-ys / alexa-random-teller.js
Created October 23, 2019 03:40
Alexa Skill Random Number Teller
// This sample demonstrates handling intents from an Alexa skill using the Alexa Skills Kit SDK (v2).
// Please visit https://alexa.design/cookbook for additional examples on implementing slots, dialog management,
// session persistence, api calls, and more.
const Alexa = require('ask-sdk-core');
const LaunchRequestHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
},
handle(handlerInput) {
@shayan-ys
shayan-ys / TodoList.js
Created December 30, 2019 23:02
Simple TodoList in ReactJS with check/uncheck by click
import cx from 'classnames';
import { Component } from 'react';
/*
assuming we wanted only ONE component, otherwise, naturally I would've make different components for each, TodoList, TodoItem, Input etc.
*/
export default class TodoList extends Component {
constructor(props) {
super(props);
@shayan-ys
shayan-ys / sockMerchant.js
Created March 1, 2020 19:13
Count pairs of socks in a merchant array - JS functional programming using variable closure
// run the code at: https://jsfiddle.net/shayan_ys/5qos4agz/
// question found on HackerRank: https://www.hackerrank.com/challenges/sock-merchant?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=warmup
function isPair(x, pairs) {
return pairs.hasOwnProperty(x);
}
var processMerchant = (function () {
var pairs = {};
var pairsCount = 0;
@shayan-ys
shayan-ys / hotel-elevators.py
Last active November 16, 2022 15:06
Hotel elevators
class Elevator:
def __init__(self, index: int, floor: int=0):
self.id = index
self.floor = floor
self.dests = []
self.dir = 0 # 1 up, -1 down, 0 idle
def update(self):
""" update status of current elevator.
Move up/down, change direction based on next destination, or stop at destination when reached