Skip to content

Instantly share code, notes, and snippets.

View viniciusCamargo's full-sized avatar
🧙‍♂️

Vinicius de Sousa Camargo viniciusCamargo

🧙‍♂️
View GitHub Profile
@viniciusCamargo
viniciusCamargo / react-closure-vs-hoc.md
Last active February 11, 2021 10:26
React: Closure x Higher Order Component
const ListItems = [
  { id: 1, address: '/link-one', text: 'Link One' },
  { id: 2, address: '/link-two', text: 'Link Two' },
  { id: 3, address: '/link-three', text: 'Link Three' },
  { id: 4, address: '/link-four', text: 'Link Four' },
  { id: 5, address: '/link-five', text: 'Link Five' }
]
@viniciusCamargo
viniciusCamargo / README.md
Last active February 11, 2021 10:26
atom: Redux-inspired state manager with simpler API
const l = console.log.bind(this)

const _a = atom({ list: [1,2,3,4], bool: false, key: 'value' })

_a.subscribe(() => l(_a.get())) // will log the state on every change

_a.get('key') // 'value'
const { key } = _a.get() // key === { key: 'value' }
@viniciusCamargo
viniciusCamargo / index.js
Created October 11, 2017 20:43
mithril - fetch example
const root1 = document.getElementById('root1')
const root2 = document.getElementById('root2')
const root3 = document.getElementById('root3')
const l = console.log.bind(this)
const api = {
path: 'https://jsonplaceholder.typicode.com',
getPostById(id) {
return m.request({ url: `${this.path}/posts/${id}` })
},
@remy
remy / next.config.js
Created July 18, 2017 18:37
Next.js configuration for dotenv and custom servers.
const webpack = require('webpack');
require('dotenv').config({
path: process.env.NODE_ENV === 'production' ? '.env.production' : '.env'
});
module.exports = {
webpack: config => {
const env = Object.keys(process.env).reduce((acc, curr) => {
acc[`process.env.${curr}`] = JSON.stringify(process.env[curr]);
@ziluvatar
ziluvatar / token-generator.js
Last active April 8, 2025 08:12
Example of refreshing tokens with jwt
/**
* Example to refresh tokens using https://github.com/auth0/node-jsonwebtoken
* It was requested to be introduced at as part of the jsonwebtoken library,
* since we feel it does not add too much value but it will add code to mantain
* we won't include it.
*
* I create this gist just to help those who want to auto-refresh JWTs.
*/
const jwt = require('jsonwebtoken');
@ralfr
ralfr / README.md
Created January 15, 2017 19:22 — forked from pdanford/README.md
Applescript to launch iTerm2 Version 3+ from OS X Finder via keyboard shortcut or Toolbar

Description

Based on info from http://peterdowns.com/posts/open-iterm-finder-service.html but with modified behavior and fixed to work with iTerm2 version 3 or later. It will not work with older versions of iTerm. The modified behavior is to open a new terminal window for each invocation instead of reusing an already open window. Update - The original author released a build script for the newer iTerm2 versions at https://github.com/peterldowns/iterm2-finder-tools that keeps the original behavior of reusing an open iTerm2 window.

To open iTerm2 at selected folder with keyboard shortcut

  1. Run Automator, select a new Service
  2. Select Utilities -> Run AppleScript
  3. Service receives selected 'folders' in 'finder.app'
  4. Paste script:

Direct copy of pre-encoded file:

$ ffmpeg -i filename.mp4 -codec: copy -start_number 0 -hls_time 10 -hls_list_size 0 -f hls filename.m3u8

ffmpeg -i data/video.mp4 -vcodec h264 -b:v 1000k -acodec mp2 data/output.mp4
@ugiacoman
ugiacoman / Client-Loading-Example.md
Last active June 24, 2022 20:50
SSR + CSR using next.js

Whether your component relies on client-side features or you are using 3rd party components that are not designed for server-side rendering, sometimes you'll want to defer rendering until on the client. For our example, we'll be using react-chart-2 to load a Doughnut chart.

Doughnut

You'll need a next project and to install chart.js + react-chartjs-2.

$ npm install --save chart.js react-chartjs-2  
@gaearon
gaearon / connect.js
Last active May 3, 2025 05:27
connect.js explained
// connect() is a function that injects Redux-related props into your component.
// You can inject data and callbacks that change that data by dispatching actions.
function connect(mapStateToProps, mapDispatchToProps) {
// It lets us inject component as the last step so people can use it as a decorator.
// Generally you don't need to worry about it.
return function (WrappedComponent) {
// It returns a component
return class extends React.Component {
render() {
return (