Skip to content

Instantly share code, notes, and snippets.

View oscarryz's full-sized avatar

Oscar Reyes oscarryz

View GitHub Profile
@oscarryz
oscarryz / Password.exs
Created March 23, 2021 16:34
Basic "while" loop in elixir
defmodule Password do
@doc """
Consider a basic password loop
it exists with a positive result if the user chooses the right password
It exists with a negative result if theuser is wrong three times
How would you code this loop
"""
def guess(attempts \\ 0)
def guess(attempts) when attempts < 3 do
guess = IO.gets "Guess: "
/* full component */
.button {
color: red;
font-family: sans-serif;
..etc. etc.
}
/* or utilities */
.red {
color: red;
@oscarryz
oscarryz / Testing express controllers.md
Last active February 13, 2020 23:23
Testing with supertest and mockery

TL;DR

  • Use mockery to inject a mock the require dependency
  • Use supertest to make an http request to the server
  • Use mocha as test runner

How to test express controllers

Setup

Source code for this example

I think StackOverflow was awesome when it started (and several years later still is) but over then it had failed to innovate / grow.

There has been attempts to create products like SO documentation, and SO jobs (and now SO teams) but they are not aligned with what made SO good in the first place. ¿What is the one thing SO was meat to solve in the first place?

This is was Jeff Atwood wrote when it was launched:

https://blog.codinghorror.com/stack-overflow-none-of-us-is-as-dumb-as-all-of-us/

Stackoverflow is sort of like the anti-experts-exchange (minus the nausea-inducing sleaze and quasi-legal search engine gaming) meets wikipedia meets programming reddit. It is by programmers, for programmers, with the ultimate intent of collectively increasing the sum total of good programming knowledge in the world. No matter what programming language you use, or what operating system you call home. Better programming is our goal.

ElementHandle {
_context:
ExecutionContext {
_client:
CDPSession {
_events: [Object],
_eventsCount: 27,
_maxListeners: undefined,
_callbacks: Map {},
_connection: [Connection],
abstract class A {
public String s() {
return this.getClass().getName();
}
}
class B extends A {
public static void main(String...args) {
System.out.println(B.class.getName());
System.out.println(new B().s());
}
{
"hash": "87b6c030d59c1c74357bb19a89d206517e09df2d"
}
//A.java
class A {
private int i;
public String toString() { return ""+ i; }
}
// B.java
class B extends A {}
// Main.java
class Main {
public static void main( String [] args ) {