Skip to content

Instantly share code, notes, and snippets.

View hongbo-miao's full-sized avatar
❣️

Hongbo Miao hongbo-miao

❣️
View GitHub Profile
class Example extends React.Component<
Props,
State,
Snapshot
> {
static getDerivedStateFromProps(
nextProps: Props,
prevState: State
): $Shape<State> | null {
// ...
@yuturiy
yuturiy / Messenger.js
Last active January 4, 2019 13:45
Messenger for React
// USING:
// import Messenger from './Messenger'
// <Messenger news={['your', 'array', 'with', 'strings', 'here']}/>
import React, { Component } from "react";
export default class Messenger extends Component {
state = {
mainMessage: "",
codeletters: "&#*+%?£@§$",
@CodeMyUI
CodeMyUI / index.html
Created January 8, 2018 01:16
Messenger
<div id="messenger"></div>
@bloc97
bloc97 / TwoMethods.md
Last active May 14, 2024 03:15
Two Fast Methods of Generating True Random Numbers on the Arduino

Two Fast Methods of Generating True Random Numbers on the Arduino

Arduino true random number generator

B. Peng

December 2017

Abstract

The AVR series microcontrollers are a collection of cheap and versatile chips that are used in many applications ranging from hobbist projects to commercial infrastructure. One major problem for some hobbists is the lack of secure random number generation on the Arduino platform. The included pseudo-random number generator (PRNG) is very easy to defeat and is useless for any crypto-related uses. One recommendation from the Arduino Reference Manual is to use atmospheric noise from the chip's analog sensor pins as seed data[6].
Unfortunately this method is extremely weak and should not be used to emulate a true random number generator (TRNG). Existing methods such as using the internal timer drift or using a dedicated generator are either too slow, requires extensive external hardware or modifications to the microcontroller's internal mech

@javilobo8
javilobo8 / download-file.js
Last active April 9, 2024 12:01
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
@nipunsadvilkar
nipunsadvilkar / Different_style_guide_python.md
Last active March 20, 2024 22:39
What is the standard Python docstring format?

Formats

Python docstrings can be written following several formats as the other posts showed. However the default Sphinx docstring format was not mentioned and is based on reStructuredText (reST). You can get some information about the main formats in that tuto.

Note that the reST is recommended by the PEP 287

There follows the main used formats for docstrings.

- Epytext

@vlucas
vlucas / encryption.js
Last active May 17, 2024 12:11
Stronger Encryption and Decryption in Node.js
'use strict';
const crypto = require('crypto');
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bits (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);
@cusspvz
cusspvz / index.js
Created November 14, 2016 15:09
require-by-kind
const PREFIX = 'synaptic'
const NpmRegExp = /^@?[a-z0-9\-]*([a-z0-9\-])?$/
export default function requireByKind ( kind, given ) {
// Avoid access to specific files by restricting the `given`
if ( given.match( NpmRegExp ) ) {
throw new Error( `only alphanumeric names are valid` )
}

@ngrx/store v3

Problems:

  • Users want to compose reducer tree across modules
  • Idea of a single reducer function makes it difficult for the library to dynamically augment the shape of the state tree
  • Turning control over to the library to build the root reducer limits the use of meta-reducers
  • Feature modules may inadvertently collide with the state of the root module
  • Library authors may want to leverage @ngrx/store in their projects and provide an easy way
import { ApolloStore } from 'apollo-client';
import { Store } from '@ngrx/store';
import { skip } from 'rxjs/operator/skip';
import { take } from 'rxjs/operator/take';
export function toApolloStore(store: Store<any>): ApolloStore {
return {
subscribe(fn: () => void): () => void {
const futureStates$ = skip.call(store, 1);