Skip to content

Instantly share code, notes, and snippets.

View profesor79's full-sized avatar
:octocat:
creating new.... ideas?

Grzegorz Bernas profesor79

:octocat:
creating new.... ideas?
View GitHub Profile
#include <Arduino.h>
#include <WiFi.h>
#define MYPORT_TX 18 //16
#define MYPORT_RX 16
#include "EspMQTTClient.h"
unsigned long previousMillis = 0;
// constants won't change:
foreach (var item in Enumerable.Range(1, 100).Select(FizzBuzz))
{
Console.WriteLine(item);
}
static string FizzBuzz(int number)
{
return (number % 3, number % 5) switch
{
(0, 0) => "FizzBuzz",
@profesor79
profesor79 / 6.js
Created March 22, 2023 16:09
no if no IF it is possible
public class _null
{
private static string[] _dividers3 = new string[] { "f", string.Empty, string.Empty };
private static string[] _dividers5 = new string[] { "bu", string.Empty, string.Empty, string.Empty, string.Empty };
private static string[] _results = new string[] { "", "fizz", "buzz", "fizzbuzz" };
public string FizzBuzz(int i)
{
_results[0] = i.ToString();
return _results[(_dividers3[i % 3] + _dividers5[i % 5]).Length];
string[] s = new string[6]{"Fizz", "Buzz", "", "", "", ""};
for (int i = 1; i <= 100; i++)
{
string output = s[(i%3)*2] + s[(i%5)+1];
Console.WriteLine(string.IsNullOrEmpty(output)? "" + i : output);
}
//orginal line
Enumerable.Range(1, 100).ToList().ForEach(i => Console.WriteLine( i % 3 * i % 5 == 0 ? (i % 3 == 0 ? "Fizz" : "") + (i % 5 == 0 ? "Buzz" : "") : i.ToString()));
// chopped so we can see it without scrolling
Enumerable
.Range(1, 100)
.ToList()
.ForEach(i => Console.WriteLine(
i % 3 * i % 5 == 0
? (i % 3 == 0 ? "Fizz" : "") + (i % 5 == 0 ? "Buzz" : "")
: i.ToString()));
public void FizzBuzz()
{
const string FIZZ = "Fizz";
const string BUZZ = "Buzz";
const string FIZZBUZZ = "FizzBuzz";
int i = 0;
while (i < 150)
{
Console.WriteLine(++i);
public void DoFizzBuzz()
{
for (int i = 1; i <= 100; i++)
{
bool fizz = i % 3 == 0;
bool buzz = i % 5 == 0;
if (fizz && buzz)
Console.WriteLine ("FizzBuzz");
else if (fizz)
Console.WriteLine ("Fizz");
public void DoFizzBuzz()
{
var combinations = new Tuple<int, string>[]
{
new Tuple<int, string> (3, "Fizz"),
new Tuple<int, string> (5, "Buzz"),
};
for (int i = 1; i <= 100; ++i)
{
@profesor79
profesor79 / refactored.js
Last active March 11, 2023 19:37
When you know what you do - then the code is better
[HttpPost]
public HttpResponseMessage UpdateElementIdManual(Parameters parameters)
{
_logger.Debug("some useful info here");
try
{
var eletran = ctx.ElementTransactions.Where(s => s.ElementNo == parameters.ElementId).First();
var dt = DateTime.Parse(eletran.DocumentPeriod + "-01");
var documentPeriod = string.IsNullOrWhiteSpace(eletran.DocumentPeriodType) ? $"{dt:MMM}-{dt:yy}" : $"{dt:MMM}-{dt:yy} {eletran.DocumentPeriodType}";
@profesor79
profesor79 / whyDRYcantStandWithUs.js
Created March 11, 2023 06:12
see this and cry, cry loudly to the heavens
[HttpPost]
public HttpResponseMessage UpdateSomething(Parameters parameters)
{
_logger.Debug("some useful info here");
try
{
var response = new HttpResponseMessage();
var eletran = ctx.ElementTransactions.Where(s => s.ElementNo == parameters.ElementId).First();