Skip to content

Instantly share code, notes, and snippets.

View r3dm1ke's full-sized avatar
🎯
Before software can be reusable it first has to be usable.

Michael Krasnov r3dm1ke

🎯
Before software can be reusable it first has to be usable.
View GitHub Profile
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import json from '@rollup/plugin-json';
export default {
input: 'index.js',
output: {
dir: 'output',
format: 'cjs'
},
const express = require('express');
const app = express();
const port = 3000;
app.get('/', (req, res) => res.send('Hello World From Unikernel!'));
app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`));
import 'package:json_annotation/json_annotation.dart';
part 'car.d.dart';
@JsonSerializable()
class Car {
String make;
String model;
// Default constructor
// Get the json string from somewhere
String carJson = '{"make": "subaru", "model": "impreza"}';
Map carMap = jsonDecode(carJson);
Car car = Car.fromJson(carMap);
// Work with car as usual
// ...
// Now send it back
String newCarJson = jsonEncode(car);
print(newCarJson); // {"make": "subaru", "model": "impreza"}
class Car {
final String make;
final String model;
// Default constructor
Car(this.make, this.model);
Car.fromJson(Map<String, dynamic> json)
: make = json['make'],
model = json['model'];
import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:todo_graphql_tutorial/api.dart';
void main() => runApp(TodoApp());
class TodoApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
import 'package:flutter/foundation.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
ValueNotifier<GraphQLClient> client = ValueNotifier(
GraphQLClient(
cache: InMemoryCache(),
link: HttpLink(uri: 'http://10.0.2.2:3000'),
),
);
FROM node:10
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
// Example with Redux Toolkit
import React from 'react';
import {createAction, createReducer, configureStore} from 'redux-toolkit';
import {Provider, useSelector, useDispatch} from 'react-redux';
const initialState = {counter: 0};
const increment = createAction('INCREMENT');
const reducer = createReducer(initialState, {
// EXAMPLE WITH REDUX
import React from 'react';
import {createStore} from 'redux';
import {Provider, useSelector, useDispatch} from 'react-redux';
const initialState = {counter: 0};
const reducer = (state=initialState, action) => {
switch (action.type) {
case 'INCREMENT':