Skip to content

Instantly share code, notes, and snippets.

@MagalyMJ
MagalyMJ / Algoritms: Sorted o(n) array
Created October 18, 2021 18:27
Solution of challenge for algoritms Encora team,
class Solution {
public:
vector<int> sortedSquares(vector<int>& nums) {
vector<int> result;
vector<int> negatives;
vector<int> positives;
for (const int& i : nums) {
if(i < 0) {
negatives.push_back(i*i);
@MagalyMJ
MagalyMJ / Algoritms: Sorted o(n) array
Created October 18, 2021 18:27
Solution of challenge for algoritms Encora team,
class Solution {
public:
vector<int> sortedSquares(vector<int>& nums) {
vector<int> result;
vector<int> negatives;
vector<int> positives;
for (const int& i : nums) {
if(i < 0) {
negatives.push_back(i*i);
@MagalyMJ
MagalyMJ / automatedStories.js
Created December 1, 2020 20:23
Automated stencil stories
/**
* Template used to render a single stencil component.
*/
function getStencilTemplate({ title, description }) {
let template = `
<div class="component-area">
<h2>${title}</h2>
${description ? '<p>' + description + '</p>' : ''}
<div class="placeholder">
<!-- the component will be inserted here -->
@MagalyMJ
MagalyMJ / global.d.ts
Created December 1, 2020 20:22
Automated stencil stories
declare module '*.md';
@MagalyMJ
MagalyMJ / my-button.stories.tsx
Created December 1, 2020 20:20
Automated stencil stories
import readme from './readme.md';
export default {
title: 'MyButton',
/**
* Notes is an optional string which will be displayed in the "Notes"
* tab for your component. It is recommended to use the generated readme,
* however any string should suffice. This supports markdown.
*/
notes: readme,
@MagalyMJ
MagalyMJ / automatedStories.js
Created December 1, 2020 20:16
Automated stencil stories
import Case from 'case';
/**
* Given a property (from stencil Component.properties) and an optional
* controlOptions object generates a control which can be used to
* dynamically update the properties of the component.
*/
function getControlForProp(prop, controlOptions) {
let defaultVal = '';
let control = {
@MagalyMJ
MagalyMJ / automatedStories.js
Last active December 1, 2020 20:18
Automated stencil stories
/**
* Template used to render a single stencil component.
*/
function getStencilTemplate({ title, description }) {
let template = `
<div class="component-area">
<h2>${title}</h2>
${description ? '<p>' + description + '</p>' : ''}
<div class="placeholder">
<!-- the component will be inserted here -->
@MagalyMJ
MagalyMJ / automatedStories.js
Created December 1, 2020 20:10
Automated stencil stories
/**
* Generates DOM nodes from states to render.
*/
function createNodes(el, elements) {
if (elements && elements.length > 0) {
elements.forEach(({ tag, innerText, props, children }) => {
let childEl = document.createElement(tag);
childEl.innerHTML = innerText;
if (props) {
Object.keys(props).forEach(prop => {
@MagalyMJ
MagalyMJ / automatedStories.js
Created December 1, 2020 20:07
Utomated stencil stories
import path from 'path';
/**
* Given a module, iterates over the exports and returns the first
* one which looks like a stencil component (using duck typing).
*/
function getComponentFromExports(_module) {
const key = Object.keys(_module).find(exportKey => {
const _export = _module[exportKey];
// does it quack like a stencil class component?
@MagalyMJ
MagalyMJ / automatedStories.js
Created December 1, 2020 20:05
Automated stencil stories
import { storiesOf } from '@storybook/html';
/**
* Iterates all of the stencil contexts and build a "config" object
* which is used to generate the individual stories.
*/
function buildStencilStories(name, componentsCtx, storiesCtx) {
const configs = buildGeneratorConfigs(componentsCtx, storiesCtx);
const stories = storiesOf(name, module);