Skip to content

Instantly share code, notes, and snippets.

@icsaba
icsaba / some-js-file.js
Created May 19, 2022 06:23
code snippet for my medium article
incrementBy(1);
@icsaba
icsaba / actions.js
Created May 19, 2022 06:22
code snippet for my medium article
export const incrementBy = context.action(
(state, value) => ({someprop: state.someprop + value})
);
export const asyncAction = context.asyncAction(
async (_, value1, value2) => ({ value1, value2})
);
@icsaba
icsaba / my-lit-component.js
Created May 19, 2022 06:21
code snippet for my medium article
class MyLitComponent extends LitElement {
static get properties() {
return {
somepropFromContext: {
type: Number,
fromContext: true
},
renamedProp: {
type: String,
@icsaba
icsaba / store.js
Last active May 19, 2022 06:20
code snippet for my medium article
context.init({
propName: someValue,
propName2: { nestedData: [] }
});
@icsaba
icsaba / thunkAction.js
Last active October 21, 2020 18:01
an actionCreator method for redux-thunk that helps you to reduce boilerplate code and creates async actions
/** Usage
*
* file: someAction.js
*
* export const SOMEVAR = 'SOMEVAR';
*
* export function fetchSomething(callbackOnDone, ...args) {
* return actionCreator({
* actionName: SOMEVAR,
* getResult(data) { return data.someProperty },
@icsaba
icsaba / firstDay.js
Last active December 8, 2019 18:59
advent of code 2019
const fs = require('fs');
const buffer = fs.readFileSync('input');
const file = buffer.toString().split('\n');
function calcConsumption(amount) {
const tmp = Math.floor(+amount / 3) - 2;
return (tmp > 0) ? tmp + calcConsumption(tmp) : 0;
}
@icsaba
icsaba / NQueens.java
Last active June 30, 2019 09:25
EAK 2 exam, parallel NQueens
package obsxvv;
import java.util.*;
import java.util.concurrent.*;
/** An immutable board of non-attacking queens. */
class Board {
/** An immutable linked list of int values. */
protected static class Node {
protected final int value;
@icsaba
icsaba / Life.java
Created June 18, 2019 17:31
EAK 2 Exam, Game of Life
package obsxvv;
import java.util.concurrent.*;
/** Game of Life. */
public class Life {
/** Invariant: <code>
from != null & to != null &
from.length == to.length != 0 &
@icsaba
icsaba / Functor.scala
Last active April 14, 2019 09:56
Examples for functional programming in Scala to demonstrate haskell codes that's been learnt on the Unversity.
import scalaz.Functor
object FunctorExample extends App{
implicit val optionFunctor: Functor[Option] = new Functor[Option] {
override def map[A, B](fa: Option[A])(f: A => B): Option[B] = fa match {
case None => None
case _ => Some(f (fa.get))
}
}
@icsaba
icsaba / Homework1.hs
Last active June 11, 2019 17:53
homeworks
module Homework1 where
data Nat = Zero | Suc Nat
deriving (Show, Eq)
addNat :: Nat -> Nat -> Nat
addNat Zero Zero = Zero
addNat a Zero = a
addNat Zero b = b
addNat (Suc a) (Suc b) = addNat (Suc(Suc a)) b