Skip to content

Instantly share code, notes, and snippets.

@manelet
manelet / sql
Created Mar 11, 2019
MySQL - Truncate table foreign key
View sql
SET foreign_key_checks = 0;
TRUNCATE TABLE seo;
SET foreign_key_checks = 1;
@manelet
manelet / encode-decode-arraybuffers.js
Last active Jan 30, 2019
Encode/decode JSON like objects to ArrayBuffers
View encode-decode-arraybuffers.js
// ENCODE
var object = { dd: "ddd", sub: { xx: "dd" }, num: 666 }
var string = JSON.stringify(object)
var uint8_array = new TextEncoder('utf-8').encode(string)
var array_buffer = uint8_array.buffer
// DECODE
var array_buffer = new Uint8Array([123,34,100,100,34,58,34,100,100,100,34,44,34,115,117,98,34,58,123,34,120,120,34,58,34,100,100,34,125,44,34,110,117,109,34,58,54,54,54,125]).buffer
var decoder = new TextDecoder('utf-8')
@manelet
manelet / streams.js
Last active Dec 13, 2018
Streams MySQL
View streams.js
const { stream } = require('@apartum/mysql-wrapper')(require('./config'))
const writeStream = require('fs').createWriteStream('./src/hola.txt')
const Transform = require('stream').Transform
const transformStream = new Transform({
objectMode: true,
highWatermark: 1,
transform (chunk, encoding, done) {
chunk.es = 'ASDASDASD'
// this.push(JSON.stringify(chunk))
done(null, JSON.stringify(chunk))
@manelet
manelet / redux-middleware-sentry.js
Created Oct 17, 2018
Redux middleware/integration for Sentry new browser module
View redux-middleware-sentry.js
// https://github.com/captbaritone/raven-for-redux/issues/82#issuecomment-421440309
/**
Middleware
*/
import thunk from 'redux-thunk';
import { applyMiddleware, createStore, compose } from 'redux';
import { init, addBreadcrumb } from '@sentry/browser';
@manelet
manelet / NoSSR.js
Created Sep 13, 2018
Wrap components with <NoSRS /> to avoid being rendered on server side
View NoSSR.js
import React from 'react'
class NoSSR extends React.Component {
state = { canRender: false }
componentDidMount () {
this.setState({ canRender: true })
}
render () {
@manelet
manelet / prepack-gentle-intro-1.md
Created May 14, 2018 — forked from gaearon/prepack-gentle-intro-1.md
A Gentle Introduction to Prepack, Part 1
View prepack-gentle-intro-1.md

Note:

When this guide is more complete, the plan is to move it into Prepack documentation.
For now I put it out as a gist to gather initial feedback.

A Gentle Introduction to Prepack (Part 1)

If you're building JavaScript apps, you might already be familiar with some tools that compile JavaScript code to equivalent JavaScript code:

  • Babel lets you use newer JavaScript language features, and outputs equivalent code that targets older JavaScript engines.
View gist:136e661fbdd73895c05365da15a4192c
{
"env": {
"es6": true,
"node": true,
"mocha": true
},
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},