Skip to content

Instantly share code, notes, and snippets.

@shalvah
shalvah / twitter-redux-example.js
Last active December 30, 2018 11:35
Basic example of how Redux could be used to manage state in a frontend app like Twitter Lite (mobile.twitter.com)
import { createStore } from 'redux';
// our reducer
const tweets = (state = {tweets: []}, action) => {
switch (action.type) {
// we'll handle only one action: when new tweets arrive
case 'SHOW_NEW_TWEETS':
state.numberOfNewTweets = action.count;
return state.tweets.concat([action.tweets]);
default:
// the base command class or interface
class Command {
handle() {
}
}
class CreateUserCommand extends Command {
constructor(user) {
super();
this.user = user;
// without event sourcing
function transferMoneyBetweenAccounts(amount, fromAccount, toAccount) {
BankAccount.where({ id: fromAccount.id })
.decrement({ amount });
BankAccount.where({ id: toAccount.id })
.increment({ amount });
}
function makeOnlinePayment(account, amount) {
BankAccount.where({ id: account.id })
module.exports = {
"env": {
"commonjs": true,
"es2021": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 13
},
"rules": {
2020-02-05 11:20:19.512 [apm-server-healthcheck] DEBUG co.elastic.apm.agent.report.ApmServerHealthChecker - Starting healthcheck to http://172.24.102.69:8200/
2020-02-05 11:20:19.522 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 10:net_cls:/
2020-02-05 11:20:19.522 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 9:memory:/
2020-02-05 11:20:19.523 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 8:hugetlb:/
2020-02-05 11:20:19.523 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 7:perf_event:/
2020-02-05 11:20:19.523 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 6:devices:/
2020-02-05 11:20:19.524 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo
2020-02-05 14:08:14.431 [apm-server-healthcheck] DEBUG co.elastic.apm.agent.report.ApmServerHealthChecker - Starting healthcheck to http://172.24.102.69:8200/
2020-02-05 14:08:14.442 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 10:memory:/
2020-02-05 14:08:14.442 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 9:hugetlb:/
2020-02-05 14:08:14.442 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 8:devices:/
2020-02-05 14:08:14.443 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 7:blkio:/
2020-02-05 14:08:14.443 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo - Could not parse container ID from '/proc/self/cgroup' line: 6:cpuacct,cpu:/
2020-02-05 14:08:14.443 [main] DEBUG co.elastic.apm.agent.impl.payload.SystemInfo -
@shalvah
shalvah / google-onetime-oauth-cli.js
Created March 15, 2020 19:42
How to get a one-time access token from Google
const TOKEN_PATH = 'token.json';
const SCOPES = ['https://www.googleapis.com/auth/spreadsheets'];
const gapi = require('googleapis');
const clientSecret = process.env.GOOGLE_CLIENT_SECRET;
const clientId = process.env.GOOGLE_CLIENT_ID;
const redirectUri = process.env.GOOGLE_REDIRECT_URI;
const oAuth2Client = new gapi.google.auth.OAuth2(clientId, clientSecret, redirectUri);
const fs = require('fs').promises;
const wordList = {
sacrilege: {popularity: 0.5207411547},
sarcasm: {popularity: 0.1913595276},
said: {popularity: 0.736293578},
sardine: {popularity: 0.2439570583},
sars: {popularity: 0.6371759558},
saw: {popularity: 0.1695272778},
say: {popularity: 0.8312312658},
scare: {popularity: 0.3623531581},
var Jimp = require('jimp');
const fileName = process.argv[2];
const width = process.argv[3];
const height = process.argv[4];
Jimp.read(fileName)
.then(photo => {
let colours = {};
for (let x = 0; x < width; x++) {
@shalvah
shalvah / .NET Activity IDs structure.md
Created July 23, 2020 14:26
Examples of System.Diagnostics.Activity structure in .NET