Skip to content

Instantly share code, notes, and snippets.

@carlows
carlows / code.rb
Created March 4, 2023 17:54
codewars exercise
class Level
# list of valid levels (skips 0)
@@levels = [*(-8..-1)] + [*(1..8)]
def self.all
@@levels
end
# Always returns a valid level
def self.next(current_level, levels_to_inc = 1)
@carlows
carlows / snippet.ex
Created September 28, 2021 12:48
Snippet
defmodule A do
def a(x), do: "hello #{x}"
def a(nil), do: "found nil"
def a(%{a: "hello"} = t), do: "found #{Map.get(t, :a)}"
end
A.a(nil)
class OddPunisher
def initialize(numbers)
@numbers = numbers
clean
end
def clean
@numbers.delete_if { |n| n.to_i.even? }
end
end
Reading = Struct.new(:date, :high, :low) do
def mean
(high + low) / 2.0
end
end
class AnnualWeather
Reading = Struct.new(:date, :high, :low)
def initialize (file_name)
@readings = []
CSV.foreach(file_name, headers: true) do |row|
@readings << Reading.new(Date.parse(row[2]),
row[10].to_f,
row[11].to_f)
require('csv')
class AnnualWeather
def initialize (file_name)
@readings = []
CSV.foreach(file_name, headers: true) do |row|
@readings << {
:date => Date.parse(row[2]),
:high => row[10].to_f,
class SuperSilliness < SillyBase
def m1 (x, y, z)
super(1, 2) # Call with 1, 2.
super(x, y) # Call with x, y.
super x, y # Same as above.
def fix_heading(heading)
heading.to_s.capitalize
end
[[14486,14511],[5892,12757],[2380,13034],[2346,11946],[3868,11481],[3474,13444],[2654,13195],[13214,14086],[3216,13248],[2791,12750],[3820,13629],[5424,11206],[11736,4754],[11805,14026],[6269,13876],[2619,12882],[7366,13788],[12190,3343],[6184,13756],[10859,10328],[4749,9003],[7535,7973],[4691,13590],[6395,5887],[8361,2399],[4082,13449],[2719,13061],[4763,1380],[9932,10074],[6634,13679],[3311,8364],[3945,10251],[8921,13784]]
import React from 'react';
import ReactDOM from 'react-dom';
import axios from 'axios';
// Necesitas crear el component como una clase
class FetchDemo extends React.Component {
constructor(props) {
super(props);
this.state = {