Share Code Quickly

What is Harigami?

Harigami is a simple source code sharing service. You can share source code by an URL which is issued after submission.
You can also run your source code online such as Python, Ruby, JavaScript and so on.
For free.Use for code review.
Preferences
anonymous No title
Python
FROM tensorflow/tensorflow:latest-gpu-py3-jupyter

USER root
RUN apt-get update && apt-get install fonts-ipaexfont libglib2.0-0 git gcc -y \
&& apt-get install libsm-dev libxrender-dev libxext-dev ffmpeg -y

RUN mkdir -p /opt/local/work \
&& chown -R ${NB_USER}. /opt/local/work

USER $NB_USER
WORKDIR /opt/local/work
COPY requirements.lock .
#RUN pip install --upgrade pip
RUN pip install -r requirements.lock
#&& conda update -n base conda \
#&& conda install --yes --channel conda-forge jupyter_contrib_nbextensions
#&& pip install -r requirements.lock
#&& conda update -n base conda \
#&& conda install --yes --channel conda-forge jupyter_contrib_nbextensions

#FROM nvidia/cuda:10.1-cudnn7-devel
anonymous No title
JavaScript
function removeAllFromState(state, name) {
    const options = resolveOption(name);
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) continue;
        const rootBucket = state[realName];
        const keys = index.keys;
        for(const id in source) {
            removeIndexMulti(source[id], id, rootBucket, keys);
        }
    }

    Vue.delete(state, options.sourceName);
}
anonymous No title
JavaScript
<template>
    <div>
            <slot/>
            <transition name="fade">
            <div class="text-xs-center" v-show="refreshing">
                <span class="progress-bg">
            <v-progress-circular
                indeterminate
                color="green"
                size="24"
                width="3"
            />
                </span>
            </div>
            </transition>
    </div>
</template>

<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator';
@Component({})
export default class Refreshable extends Vue {
    @Prop() refreshing?: boolean;
}

</script>

<style scoped lang="scss">
.text-xs-center {
    z-index: 2;
    vertical-align: middle;
    position: absolute;
    top: 4rem;
    left: 0;
    width: 100%;
}

.progress-bg {
    display: inline-flex;
    background-color: #fff;
    width: 50px;
    height: 50px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    border-radius: 25px;
    box-shadow:0px 0px 10px rgba(0,0,0,0.25);
}
.fade-enter-active, .fade-leave-active {
  transition: opacity .25s;
}
.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
  opacity: 0;
}
</style>

anonymous No title
JavaScript
function resolveOption(optname) {
    const option = opts[optname];
    if(!option.sourceName) option.sourceName = optname;
    if(!option.primary) option.primary = 'id';
    if(!option.prefix) option.prefix = optname.toLowerCase();
    return option;
}

function addValueToState(state, optname, value) {
    const options = resolveOption(optname);
    if(!state[options.sourceName]) Vue.set(state, options.sourceName, {});

    const source = state[options.sourceName];

    // Add to source
    Vue.set(source, value[options.primary], value);

    // build index
    addIndexToState(state, optname, value[options.primary]);
}

function addIndexToState(state, optname, id) {
    const options = resolveOption(optname);
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    const v = source[id];

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) Vue.set(state, realName, {});
        const rootBucket = state[realName];
        const keys = index.keys;
        buildIndexMulti(v, v[options.primary], rootBucket, keys);
    }
}

function removeIndexMulti(v, id, bucket, keys, i = 0) {
    const key = v[keys[i]];
    if(keys.length-1 == i) {
        bucket[key] = bucket[key].filter(x => x != id);
    }
    else {
        removeIndexMulti(v, id, bucket[key], keys, i+1);
    }
}

function removeValueFromState(state, optname, id) {
    const options = resolveOption(optname);
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    // remove for each index
    removeIndexFromState(state, optname, id);

    // remove from source
    Vue.delete(source, id);
}

function removeIndexFromState(state, optname, id) {
    const options = resolveOption(optname);
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    const v = source[id];

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) Vue.set(state, realName, {});
        const rootBucket = state[realName];
        const keys = index.keys;
        removeIndexMulti(v, v[options.primary], rootBucket, keys);
    }
}
anonymous No title
Python
//@version=3
study("Hull cross and ATR", shorttitle="H&ATR", overlay=true)
keh=input(title="Hull Length",type=integer,defval=52)
length = input(title="ATR Length", defval=46, minval=1)
smoothing = input(title="ATR Smoothing", defval="WMA", options=["RMA", "SMA", "EMA", "WMA"])
p=input(ohlc4,type=source,title="Price data")
n2ma=2*wma(p,round(keh/2))
nma=wma(p,keh)
diff=n2ma-nma
sqn=round(sqrt(keh))
n2ma1=2*wma(p[1],round(keh/2))
nma1=wma(p[1],keh)
diff1=n2ma1-nma1
sqn1=round(sqrt(keh))
n1=wma(diff,sqn)
n2=wma(diff1,sqn)
ma_function(source, length) => 
    if smoothing == "RMA"
        rma(p, length)
    else
        if smoothing == "SMA"
            sma(p, length)
        else
            if smoothing == "EMA"
                ema(p, length)
            else
                wma(p, length)
plot(ma_function(tr(true), length), title = "ATR", color=#00000000, transp=50)
exitLong = n1<n2
exitShort = n1>n2
longCondition = ma_function(tr(true), length)<p and p>p[length] and n1>n2
shortCondition = ma_function(tr(true), length)>p and p<p[length] and n1<n2

_state = 0
_prev  = nz(_state[1])
_state := _prev
if _prev == 0
    if longCondition 
        _state := 1
    if shortCondition 
        _state := 2
if _prev == 1
    if exitLong
        _state := 0
if _prev == 2
    if exitShort
        _state := 0
_bLongEntry  = (_state == 1 and _prev == 0)
_bShortEntry = (_state == 2 and _prev == 0)
_bLclose  = (_state == 0 and _prev == 1)
_bSclose   = (_state == 0 and _prev == 2)

alertcondition(_bLongEntry, title="BUY", message="Buy")
alertcondition(_bShortEntry, title="SELL", message="Sell")
alertcondition(_bLclose or _bSclose, title="CLOSE", message="Close")
bgcolor(_bLongEntry?lime:na, transp=30)
bgcolor(_bShortEntry?red:na, transp=30)
bgcolor(_bLclose or _bSclose?yellow:na, transp=30)
anonymous No title
Python
//@version=3
strategy("Hull cross and ATR", shorttitle="H&ATR", overlay=true)
keh=input(title="Hull Length",type=integer,defval=52)
length = input(title="ATR Length", defval=46, minval=1)
smoothing = input(title="ATR Smoothing", defval="WMA", options=["RMA", "SMA", "EMA", "WMA"])
p=input(ohlc4,type=source,title="Price data")
n2ma=2*wma(p,round(keh/2))
nma=wma(p,keh)
diff=n2ma-nma
sqn=round(sqrt(keh))
n2ma1=2*wma(p[1],round(keh/2))
nma1=wma(p[1],keh)
diff1=n2ma1-nma1
sqn1=round(sqrt(keh))
n1=wma(diff,sqn)
n2=wma(diff1,sqn)
ma_function(source, length) => 
    if smoothing == "RMA"
        rma(p, length)
    else
        if smoothing == "SMA"
            sma(p, length)
        else
            if smoothing == "EMA"
                ema(p, length)
            else
                wma(p, length)
plot(ma_function(tr(true), length), title = "ATR", color=black, transp=50)
closelong = n1<n2
if (closelong)
    strategy.close("buy")
closeshort = n1>n2
if (closeshort)
    strategy.close("sell")
if (ma_function(tr(true), length)<p and p>p[length] and n1>n2)
    strategy.entry("buy", strategy.long, comment="BUY")
if (ma_function(tr(true), length)>p and p<p[length] and n1<n2)
    strategy.entry("sell", strategy.short, comment="SELL")
anonymous No title
JavaScript
function addValueToState(state, options, value) {
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    // Add to source
    Vue.set(source, value[options.primary], value);

    // build index
    addIndexToState(state, options, value[options.primary]);
}

function addIndexToState(state, options, id) {
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    const v = source[id];

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) Vue.set(state, realName, {});
        const rootBucket = state[realName];
        const keys = index.keys;
        buildIndexMulti(v, v[options.primary], rootBucket, keys);
    }
}

function removeIndexMulti(v, id, bucket, keys, i = 0) {
    const key = v[keys[i]];
    console.log(bucket);
    if(keys.length-1 == i) {
        bucket[key] = bucket[key].filter(x => x != id);
    }
    else {
        removeIndexMulti(v, id, bucket[key], keys, i+1);
    }
}

function removeValueFromState(state, options, id) {
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    // remove for each index
    removeIndexFromState(state, options, id);

    // remove from source
    Vue.delete(source, id);
}

function removeIndexFromState(state, options, id) {
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    const v = source[id];

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) Vue.set(state, realName, {});
        const rootBucket = state[realName];
        const keys = index.keys;
        removeIndexMulti(v, v[options.primary], rootBucket, keys);
    }
}
anonymous No title
JavaScript
const shiftOptions: EntityOptions = {
    sourceName: 'shifts',
    primary: 'id',
    prefix: 'shift',
    indexes: {
        'idx1': { keys: [ 'branch_id', 'yearmonth', 'day' ] }
    }
}


function buildIndexMulti(v, id, bucket, keys, i = 0) {
    if(keys.length == i) {
        Vue.set(bucket, bucket.length, id);
    }
    else {
        const key = v[keys[i]]
        if(!bucket[key]) Vue.set(bucket, key, keys.length - i >= 2 ? {} : []);
        buildIndexMulti(v, id, bucket[key], keys, i+1);
    }
}

function addArrayToState(state, options, array) {
    if(!state[options.sourceName]) Vue.set(state, options.sourceName, {});

    const source = state[options.sourceName];
    const primary = options.primary;

    // build source
    for(const v of array) {
        // build source
        Vue.set(source, v[options.primary], v);
    }

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) Vue.set(state, realName, {});
        const rootBucket = state[realName];
        const keys = index.keys;
        for(const v of array) {
            buildIndexMulti(v, v[primary], rootBucket, keys);
        }
    }
}
anonymous No title
JavaScript
const MyEventEmitter = function() {
    this.callbackPool = {};
}

MyEventEmitter.prototype.on = function(type, callback) {
    this.callbackPool[type] = callback;
}

MyEventEmitter.prototype.emit = function(type, arg) {
    const sliced = [];
    for(let i = 1; i < arguments.length; i++) sliced.push(arguments[i]);
    if(this.callbackPool) this.callbackPool[type].apply(undefined, sliced);
}
anonymous No title
Python
//@version=3
study(title="MTF Bollinger Bands", shorttitle="MTF 2 BB", overlay=true)

onoffA = input(true, "BB1 ON/OFF")
resA = input(title='BB1時間足 (BB1 Time Frame)', type=resolution, defval="60")
sigmaA = input(1,title='BB1偏差 (BB1 Sigma)', step=1, minval=1, maxval=3)
onoffB = input(true, "BB2 ON/OFF")
resB = input(title='BB2時間足 (BB1 Time Frame)', type=resolution, defval="60")
sigmaB = input(2,title='BB2偏差 (BB2 Sigma)', step=1, minval=1, maxval=3)

devA = security(tickerid, resA, stdev(close,20))
basisA = security(tickerid, resA, sma(close,20))
devB = security(tickerid, resB, stdev(close,20))
basisB = security(tickerid, resB, sma(close,20))

upper_1 = onoffA ? (basisA + devA * sigmaA) : na
lower_1 = onoffA ? (basisA - devA * sigmaA) : na
upper_2 = onoffB ? (basisB + devB * sigmaB) : na
lower_2 = onoffB ? (basisB - devB * sigmaB) : na

plot(basisA, color=red,title='BB1 Basis')
plot(basisB, color=orange,title='BB2 Basis')
u1 = plot(upper_1, color=blue,title='BB1 Upper')
l1 = plot(lower_1, color=blue,title='BB1 Lower')
u2 = plot(upper_2, color=green,title='BB2 Upper')
l2 = plot(lower_2, color=green,title='BB2 Lower')
fill(u1,l1, color=yellow, transp=90,title='BB1')
fill(u2,l2, color=yellow, transp=90,title='BB2')
年末年始は機械学習・深層学習を勉強しませんか?
広告
未経験から最短でエンジニアへの転職を目指すなら