Skip to content

Instantly share code, notes, and snippets.

View eiyaya's full-sized avatar

stephen zhen eiyaya

  • Beijing. China.
View GitHub Profile
@eiyaya
eiyaya / promisepipe.js
Created May 8, 2016 15:18
convert pipe to promise
'use strict';
const fs = require('fs');
const co = require('co');
const unzip = require('unzip');
const promisePipe = require("promisepipe");
/*
fs.createReadStream('t.zip')
.pipe(unzip.Extract({ path: 'output' }).on('close',function (){
console.log('done');
@eiyaya
eiyaya / webpack.config.js
Created June 17, 2016 05:38
webpack config
var webpack = require('webpack');
module.exports = {
plugins: [
// http://stackoverflow.com/questions/29080148/expose-jquery-to-real-window-object-with-webpack
new webpack.ProvidePlugin({
// Automtically detect jQuery and $ as free var in modules
// and inject the jquery library
// This is required by many jquery plugins
jquery: "jquery",
@eiyaya
eiyaya / inline.jsx
Created January 24, 2017 06:41
react inline function
<Route path='dashboard' component={props => <MyComponent myProp='some-value' {...props} />} />
@eiyaya
eiyaya / deployment-tool-ansible-puppet-chef-salt.md
Created February 16, 2017 02:10 — forked from jaceklaskowski/deployment-tool-ansible-puppet-chef-salt.md
Choosing a deployment tool - ansible vs puppet vs chef vs salt

Requirements

  • no upfront installation/agents on remote/slave machines - ssh should be enough
  • application components should use third-party software, e.g. HDFS, Spark's cluster, deployed separately
  • configuration templating
  • environment requires/asserts, i.e. we need a JVM in a given version before doing deployment
  • deployment process run from Jenkins

Solution

@eiyaya
eiyaya / recover_source_code.md
Created March 12, 2017 04:31 — forked from simonw/recover_source_code.md
How to recover lost Python source code if it's still resident in-memory

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
import asyncio
import json
import logging
import aiohttp
from aiohttp import HttpProcessingError, ClientSession
# setting up logger
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
@eiyaya
eiyaya / cis.go
Created March 30, 2017 06:14
calculate jenkins build time
package controllers
import (
"fmt"
"log"
"os"
xmlpath "gopkg.in/xmlpath.v1"
_ "github.com/go-sql-driver/mysql"
@eiyaya
eiyaya / run_script_from_string.js
Created May 14, 2017 10:53
node run code from string
'use strict';
var vm = require('vm')
exports.getData = function* (id) {
this.query.id;
global.self = this;
var result = []
let raw = `foo = function*(){ \
let apiResult = yield self.app.urllib.requestThunk(self.app.config.dataServiceUrl + '/data/zhima/1'); \
return JSON.parse(apiResult.data); \
@eiyaya
eiyaya / reader1.go
Created October 18, 2018 23:51
read from tcp conn
buff := make([]byte, 1024)
c := bufio.NewReader(conn)
for {
// read a single byte which contains the message length
size, err := c.ReadByte()
if err != nil {
return err
}
@eiyaya
eiyaya / tcp_timeout.go
Created October 19, 2018 04:05 — forked from hongster/tcp_timeout.go
Golang example on handling TCP connection and setting timeout.
package main
import (
"fmt"
"net"
"time"
"bufio"
)
func handleConnection(conn net.Conn) {