This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const useArrayState = (initialState = []) => { | |
| const [state, setState] = useState(initialState) | |
| const add = (newValue) => { | |
| setState((currentState) => [...currentState, newValue]) | |
| } | |
| const remove = (index) => { | |
| setState((currentState) => { | |
| const newState = [...currentState] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "log" | |
| "time" | |
| ) | |
| func main() { | |
| queue := NewQueue("amqp://guest:guest@localhost:5672/", "hello") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if [[ $OSTYPE == "darwin"* ]]; then | |
| full_size=$(find $build_dir ! -type d -print0 | xargs -0 stat -f '%z' | awk '{sum += $1} END{print sum}') | |
| else | |
| full_size=$(du -sb $build_dir | awk '{print $1}') | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function formatBytes(bytes,decimals) { | |
| if(bytes == 0) return '0 Bytes'; | |
| var k = 1024, | |
| dm = decimals || 2, | |
| sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], | |
| i = Math.floor(Math.log(bytes) / Math.log(k)); | |
| return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; | |
| } | |
| // Usage: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| node -e "console.log(require('crypto').randomBytes(256).toString('base64'));" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const chalk = require('chalk'); | |
| /** | |
| * Adds mark check symbol | |
| */ | |
| function addCheckMark(callback) { | |
| process.stdout.write(chalk.green(' ✓')); | |
| if (callback) callback(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const readline = require('readline'); | |
| /** | |
| * Adds an animated progress indicator | |
| * | |
| * @param {string} message The message to write next to the indicator | |
| * @param {number} amountOfDots The amount of dots you want to animate | |
| */ | |
| function animateProgress(message, amountOfDots) { | |
| let i = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package logging | |
| import ( | |
| "github.com/rs/zerolog" | |
| "github.com/rs/zerolog/log" | |
| "gopkg.in/natefinch/lumberjack.v2" | |
| "os" | |
| "path" | |
| "io" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "os" | |
| func createDirIfNotExists(path string) error { | |
| if _, err := os.Stat(path); os.IsNotExist(err) { | |
| return os.Mkdir(path, os.ModeDir|0755) | |
| } | |
| return nil | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useRef, useReducer } from 'react' | |
| import { fetchJson } from 'apis' | |
| export function useFetchWithCache({ | |
| url, | |
| options, | |
| }) { | |
| const cache = useRef({}) |
NewerOlder