Skip to content

Instantly share code, notes, and snippets.

@rodrigolira
rodrigolira / Dropdown.js
Last active May 24, 2023 15:27
Animated dropdown native Web Component
class Dropdown extends HTMLElement {
constructor() {
super();
this._documentClick = this._closeOnDocumentClick.bind(this);
this._dropdownAlignment = "left";
this._open = false;
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = /*html*/`
@rodrigolira
rodrigolira / sample-rxjs-operator.markdown
Last active April 22, 2019 02:02
Sample RxJs Operator
@rodrigolira
rodrigolira / flexbox-tutorial-from-academind.markdown
Created April 8, 2019 00:59
Flexbox Tutorial from Academind
@rodrigolira
rodrigolira / MyDatabaseSeeder.cs
Created December 3, 2018 00:29
Seeding data on Asp.Net Core 2.0
public class MyDatabaseSeeder
{
public static async Task SeedAsync(MyDbContext context)
{
if(!context.Foos.Any())
{
context.Foos.AddRange(GetPreconfiguredFoos());
await context.SaveChangesAsync();
}
@rodrigolira
rodrigolira / unhandled_exceptions_on_async_void_methods.cs
Last active June 21, 2018 03:28
C# - Understanding unhandled exception on "async void" methods
// This file simulates an event handler executing an async method.
// LoginAsync() throws an unhandled exception. The compiler generated code has no way to schedule a continuation for the Task.
// There isn't anyway it can signal a faulted state. We can't "await" LoginAsync() because the method doesn't return anything.
// To solve this problem, we can change LoginAsync signature, replacing "void" with "Task".
private void LoginButton_Click(object sender, EventArgs args) {
try {
LoginAsync();
} catch (Exception) {
}
@rodrigolira
rodrigolira / isPalindrome.js
Last active June 19, 2018 01:41
Detecting Palindromes in javascript
// Implement a function that will receive a string as a parameter and will return
// true or false indicating whether the text is a palindrome (spelled the same way
// forward and backwards). The solution should avoid the use of regular expressions.
function isPalindrome(text) {
// TODO: convert accented characters to its ASCII equivalent character
// so it could be used by other languages.
var allowedChars = "abcdefghijklmnopqrstuvwxyz0123456789";
var lowercaseText = text.toLowerCase();
var forwardWordArray = [];
@rodrigolira
rodrigolira / harmlessRansomNote.js
Last active June 18, 2018 00:55
Harmless Ransom Note algorithm implementation in javascript
// Implementation attempt of the Harmless Ransom Note algorithm.
// Create a function that receive two string parameters.
// The function should return "true" when the text int "noteText" can be created
// from words presented on "magazineText". It should return "false" otherwise.
function harmlessRansomNote(noteText, magazineText) {
var noteWords = noteText.split(" ");
var magazineWords = magazineText.split(" ");
var allWordsFound = true;
for (var i = 0; i < noteWords.length; i++) {
@rodrigolira
rodrigolira / fizzbuzz.js
Last active June 16, 2018 21:02
Implementing the FizzBuzz algorithm in Javascript
// Create a funcion that will receive an integer number as a parameter and output to the log every number from 1 to the parameter.
// For each number divisible by 3, it should log the word "Fizz" instead of the number.
// For each number divisible by 5, it should log the word "Buzz" instead of the number.
// For each number divisible by 3 and 5, it should log the word "FizzBuzz" instead of the number.
function fizzBuzz(num) {
for (var i = 1; i <= num; i++) {
if (i % 15 == 0) console.log("FizzBuzz")
else if (i % 3 == 0) console.log("Fizz")
else if (i % 5 == 0) console.log("Buzz")
else console.log(i);