Skip to content

Instantly share code, notes, and snippets.

View markodayan's full-sized avatar
🍑

Mark Odayan markodayan

🍑
View GitHub Profile
@markodayan
markodayan / timingattackprotect.ts
Created November 17, 2021 20:31
Timing Attack protection in Nestjs project
import { BasicStrategy as Strategy } from 'passport-http';
import { Injectable, InternalServerErrorException, UnauthorizedException } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { ConfigService } from '@nestjs/config';
import { timingSafeEqual } from 'crypto';
@Injectable()
export class AdminBasicStrategy extends PassportStrategy(Strategy) {
constructor(private readonly configService: ConfigService) {
@markodayan
markodayan / mocha.sh
Created November 12, 2021 19:54
Mocha test location (all wildcard .spec.ts files in a directory which may be nested)
"test": "mocha \"test/**/*.spec.js\""
# TypeScript development
"test": "mocha -r ts-node/register \"src/test/**/*.spec.ts\""
@markodayan
markodayan / tsconfig.json
Last active November 8, 2021 18:30
Some common backend Typescript configs
{
"compilerOptions": {
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"outDir": "./dist", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"skipLibC
@markodayan
markodayan / package-sub.json
Last active December 30, 2021 15:04
TypeScript Starter script
{
"main": "index.js",
"scripts": {
"clean": "rimraf dist",
"start": "NODE_ENV=production node -r ts-node/register/transpile-only -r tsconfig-paths/register ./dist/index.js",
"build": "npm run clean && tsc",
"dev": "NODE_ENV=development ts-node-dev -r tsconfig-paths/register ./src/index.ts",
"test": "mocha -r ts-node/register \"src/test/**/*.spec.ts\"",
"pm2:dev": "npm run build && pm2 start pm2_dev.config.js",
"pm2:prod": "npm run build && pm2 start pm2_prod.config.js",
@markodayan
markodayan / Dai.sol
Created October 16, 2021 08:00
Dai contract
pragma solidity >=0.5.12;
// FIXME: This contract was altered compared to the production version.
// It doesn't use LibNote anymore.
// New deployments of this contract will need to include custom events (TO DO).
contract Dai {
// --- Auth ---
mapping (address => uint) public wards;
function rely(address guy) external auth { wards[guy] = 1; }
@markodayan
markodayan / commands.sh
Last active December 11, 2021 13:03
repetitive stuff with node
npm init -y
echo "node_modules\n.env" > .gitignore
echo "# Node.js Boilerplate Sample" > README.md
touch .env
mkdir -p src/test && touch src/index.js
mkdir -p src/lib
mkdir -p .github/workflows && touch .github/workflows/actions.yaml
mkdir .vscode && touch .vscode/settings.json
touch .prettierrc
git init
@markodayan
markodayan / Example.js
Last active June 21, 2024 09:33
EIP-712 Signing
const ethUtil = require('ethereumjs-util');
const abi = require('ethereumjs-abi');
const chai = require('chai');
const typedData = {
types: {
EIP712Domain: [
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' },
{ name: 'chainId', type: 'uint256' },
@markodayan
markodayan / App.js
Last active August 6, 2020 13:46
advanced App.js for Multiple RN Navigation Options
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
// React Navigation
import { createAppContainer, createSwitchNavigator } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import { createBottomTabNavigator } from 'react-navigation-tabs';
// Screen
import AccountScreen from './src/screens/AccountScreen';
import DashboardScreen from './src/screens/DashboardScreen';
import IndexScreen from './src/screens/IndexScreen';
@markodayan
markodayan / BlogContext.js
Created August 5, 2020 10:51
Automating Context Creation (Useful but Complex!)
import React, { createContext, useState, useReducer } from 'react';
import createDataContext from './createDataContext';
const initialState = [];
const blogReducer = (state, action) => {
switch (action.type) {
case 'ADD_BLOGPOST':
return [...state, { title: `Blog Post #${state.length + 1}` }];
@markodayan
markodayan / App.js
Last active August 6, 2020 13:11
React Native Expo Project Setup
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { createAppContainer, createSwitchNavigator } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import { createBottomTabNavigator } from 'react-navigation-tabs';
// Screen
import IndexScreen from './src/screens/IndexScreen';
const navigator = createStackNavigator(