Skip to content

Instantly share code, notes, and snippets.

@manelet
manelet / sql
Created March 11, 2019 12:13
MySQL - Truncate table foreign key
SET foreign_key_checks = 0;
TRUNCATE TABLE seo;
SET foreign_key_checks = 1;
@manelet
manelet / encode-decode-arraybuffers.js
Last active January 30, 2019 18:44
Encode/decode JSON like objects to ArrayBuffers
// 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 December 13, 2018 14:28
Streams MySQL
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 October 17, 2018 10:43
Redux middleware/integration for Sentry new browser module
// 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 September 13, 2018 07:18
Wrap components with <NoSRS /> to avoid being rendered on server side
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 18:08 — forked from gaearon/prepack-gentle-intro-1.md
A Gentle Introduction to Prepack, Part 1

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.
{
"env": {
"es6": true,
"node": true,
"mocha": true
},
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},