Harigami
ログイン
Harigamiは、ログイン不要のコード共有サービスです。コードの投稿後に発行されるURLでコードを共有できます。
PythonやRubyなど一部の言語は、投稿後にオンラインで実行することもできます。
誰でも無料で使えて、広告もありません。コードレビューやスニペットの代わりに使ってみてください。


詳細設定
+
anonymous タイトルなし
Go
package main
import (
	"fmt"
	"strings"
	"os"
)
func main() {
	args := os.Args
	vt := var_type()
	vtype := strings.Split(vt, ",")
	support_vtype := []string{"int", "char", "double"}
	if len(args) == 2 {
		filename := args[1]
		file, err := os.Open(filename)
		if err != nil{
			fmt.Printf("No Such file : %s", filename)
			os.Exit(0)
		}
		nfilename,ext := get_ext_filename(filename)
		if ext != "sl"{
			fmt.Println(filename, "is not SasaLan File")
			os.Exit(0)
		}
		buf := make([]byte, 1024)
		var add_code string
		for {
			n,err := file.Read(buf)
			if n == 0{
				break
			}
			if err != nil{
				fmt.Println("Read Error")
				break
			}
			code := string(buf[:n])
			add_code += code
		}
		nl_split := strings.Split(add_code, "\n")
		size := len(nl_split)
		var var_string string
		var var_type_s string
		in_if, in_func := "0", "0"
		var func_code string
		var main_code string
		main_code += "#include <stdio.h>\nint main(void){\n"
		for i := 0;i < size;i++{
			code := nl_split[i]
			space_split := strings.Split(code, " ")
			if code == ""{
				continue
			}
			if string(code[0]) == "#" {
				var comment_value string
				for i := 0;i < len(code);i++ {
					if i == 0{
						continue
					} else {
						comment_value += string(code[i])
					}
				}
				add_code := "/*" + comment_value + "*/\n"
				main_code += add_code
			} else if len(space_split) >= 2 {
				if space_split[0] == "if" {
					var judge_formula string
					for i,value := range space_split {
						if i == 0 {
							continue
						} else if i == 1 {
							judge_formula += value
						} else {
							judge_formula += " " + value
						}
					}
					add_code := if_code(judge_formula)
					in_if += ",1"
					main_code += add_code
				}
			} else if code == "e" {
				if_sp, func_sp := strings.Split(in_if, ","), strings.Split(in_func, ",")
				lengh1, lengh2 := len(if_sp) - 1, len(func_sp) - 1
				ires, fres := if_sp[lengh1], func_sp[lengh2]
				if ires == "1" {
					main_code += "}\n"
				} else if fres == "1" {
					func_code += "}"
				}
			}
			if space_split[0] == "pr" {
				var pr_value string
				for i := 1;i < len(code);i++{
					if i == 0 || i == 1 || i == 2{
						continue
					} else {
						pr_value += string(code[i])
					}
				}
				add_code := pr_code(pr_value, strings.Split(var_string, ","), strings.Split(var_type_s, ","))
				main_code += add_code
			}
			var_split1 := strings.Split(code, string(vtype[0]))
			var_split2 := strings.Split(code, string(vt[1]))
			var_split3 := strings.Split(code, "f:")
			if var_split1[0] == "" {
				var_name_value := var_split1[1]
				line_split1 := strings.Split(var_name_value, "=")
				var_name,var_value := line_split1[0], line_split1[1]
				lengh1, lengh2 := len(strings.Split(var_name, " ")), len(strings.Split(var_value, " "))
				var vname string
				var vvalue string
				if lengh1 == 2 && lengh2 == 2{
					var_name, var_value := strings.Split(var_name, " ")[0], strings.Split(var_value, " ")[1]
					vname += var_name
					vvalue += var_value
				}
				var_type := support_vtype[0]
				add_code := var_code(var_type, vname, vvalue)
				if len(var_string) == 0{
					var_string += vname
				} else {
					var_string += "," + vname
				}
				if len(var_type_s) == 0{
					var_type_s += var_type
				} else {
					var_type_s += "," + var_type
				}
				main_code += add_code
			} else if var_split2[0] == "s" {
				var_name_value := var_split2[1]
				line_split1 := strings.Split(var_name_value, "=")
				var_name,var_value := line_split1[0], line_split1[1]
				lengh1, lengh2 := len(strings.Split(var_name, " ")), len(strings.Split(var_value, " "))
				var vname string
				var vvalue string
				if lengh1 >= 2 && lengh2 >= 2 {
					var_name := strings.Split(var_name, " ")[0]
					var_value_sp := strings.Split(var_value, " ")
					var res string
					for i := 0;i < len(var_value_sp);i++ {
						if i == 0{
							continue
						} else if i == 1{
							res += var_value_sp[i]
						} else {
							res += " " + var_value_sp[i]
						}
					}
					vvalue += res
					vname += var_name
				} else {
					vname += var_name
					vvalue += var_value
				}
				var_type := support_vtype[1]
				add_code := var_code(var_type, vname, vvalue)
				if len(var_string) == 0{
					var_string += vname
				} else {
					var_string += "," + vname
				}
				if len(var_type_s) == 0{
					var_type_s += var_type
				} else {
					var_type_s += "," + var_type
				}
				main_code += add_code
			} else if var_split3[0] == ""{ //float && コード変換
				var_name_value := var_split3[1]
				line_split1 := strings.Split(var_name_value, "=")
				var_name, var_value := line_split1[0], line_split1[1]
				lengh1, lengh2 := len(strings.Split(var_name, " ")), len(strings.Split(var_value, " "))
				var vname string
				var vvalue string
				if lengh1 >= 2 && lengh2 >= 2 {
					var_name := strings.Split(var_name, " ")[0]
					var_value_sp := strings.Split(var_value, " ")
					var res string
					for i,value := range var_value_sp {
						if i == 0 {
							continue
						} else if i == 1 {
							res += value
						} else {
							res += " " + value
						}
					}
					vname += var_name
					vvalue += res
				} else {
					vname += var_name
					vvalue += var_value
				}
				var_type := support_vtype[2]
				add_code := var_code(var_type, vname, vvalue)
				if len(var_string) == 0{
					var_string += vname
				} else {
					var_string += "," + vname
				}
				if len(var_type_s) == 0{
					var_type_s += var_type
				} else {
					var_type_s += "," + var_type
				}
				main_code += add_code
			}
		}
		if string(main_code[len(main_code) - 1]) !="}" {
			main_code += "}"
		}
		cfilename := nfilename + ".c"
		nfile,err := os.Create(cfilename)
		if err != nil{
			fmt.Println("Write Error")
			os.Exit(0)
		}
		nfile.Write(([]byte)(main_code))
		fmt.Printf("Output C File : %s\n", cfilename)
	} else {
		fmt.Println("sasalan [filename]")
		os.Exit(0)
	}
}
func get_ext_filename(filename string) (string, string) {
	split_arr := strings.Split(filename, ".")
	max_lengh := len(split_arr) - 1
	ext := split_arr[max_lengh]
	return split_arr[0],ext
}
func var_type() string {
	filename := "doc/var_type"
	var code string
	file,err := os.Open(filename)
	if err != nil{
		fmt.Println("Error")
	}
	buf := make([]byte, 1024)
	for {
		n,err := file.Read(buf)
		if n == 0 {
			break
		}
		if err != nil{
			fmt.Println("Read Error")
		}
		ncode := string(buf[:n])
		code += ncode
	}
	tl := strings.Split(code, "\n")[0]
	return tl
}
func var_code(var_type string, var_name string, var_value string) string {
	var res string
	if var_type == "int" {
		code := fmt.Sprintf("int %s = %s;\n", var_name, var_value)
		res += code
	} else if var_type == "char"{
		code := fmt.Sprintf("char %s[] = %s;\n", var_name, var_value)
		res += code
	} else if var_type == "double" {
		code := fmt.Sprintf("float %s = %sf;\n", var_name, var_value)
		res += code
	}
	return res
}
func pr_code(put_string string, var_array []string, var_type_array []string) string {
	var judge1 rune = '"'
	var res string
	pr_split1 := strings.Split(put_string, string(judge1))
	join_split1 := strings.Split(put_string, ",")
	if len(pr_split1) == 3 {
		res += fmt.Sprintf("printf(%s);\n", put_string)
		return res
	}
	if len(join_split1) >= 2 {
		base := "printf(" + string(judge1)
		var after_str string
		judge2 := "0"
		for _,v := range join_split1 {
			fmt.Println(v)
			if string(v[0]) == string(judge1) {
				judge2 += ",0"
				if len(after_str) == 0 {
					after_str += v
				} else {
					after_str += "," + v
				}
				base += "%s"
				continue
			} else if string(v[len(v) - 1]) == string(judge1) {
				judge2 += ",1"
				if len(after_str) == 0 {
					after_str += v
				} else {
					after_str += "," + v
				}
			} else if strings.Split(judge2, ",")[len(strings.Split(judge2, ",")) - 1] == "1" {
				if len(after_str) == 0 {
					after_str += v
				} else {
					after_str += "," + v
				}
			} else {
				if len(after_str) == 0 {
					after_str += v
				} else {
					after_str += "," + v
				}
				var vtype string
				var res2 string
				for i := 0;i < len(var_array);i++ {
					if var_array[i] == v {
						res2 += "comp"
						vtype += var_type_array[i]
						break
					} else {
						res2 += "not"
					}
				}
				if res2 == "not" {
					fmt.Printf("There is not variable %s", v)
					os.Exit(0)
				}
				if vtype == "int" {
					base += "%d"
				} else if vtype == "char" {
					base += "%s"
				} else if vtype == "double" {
					base += "%f"
				}
				continue
			}
		}
		base += string(judge1) + ", " + after_str + ");\n"
		return base
	}
	var res2 string
	var vtype string
	for i := 0;i < len(var_array);i++ {
		if var_array[i] == put_string{
			res2 += "comp"
			vtype += var_type_array[i]
			break
		} else {
			res2 += "not"
		}
	}
	if res2 == "not" {
		fmt.Printf("There is not variable %s", put_string)
		os.Exit(0)
	} 
	if vtype == "int" {
		 code := "printf(" + string(judge1) + "%d" + string(judge1) + ", " + put_string + ");\n"
		 res += code
	} else if vtype == "char" {
		code := "printf(" + string(judge1) + "%s" + string(judge1) + ", " + put_string + ");\n"
		res += code
	} else if vtype == "double" {
		code := "printf(" + string(judge1) + "%f" + string(judge1) + ", " + put_string + ");\n"
		res += code
	}
	return res
}
func if_code(judge_formula string) string {
	return fmt.Sprintf("if (%s) {\n", judge_formula)
}
  • 0
  • 0
Tomoaki Sugiyama タイトルなし
Python
  • 0
  • 0
anonymous タイトルなし
Python
//@version=3
study("MTF 8 SMA/EMA", overlay=true)

// SMA or EMA
SEswitch = input(title="on:EMA off:SMA", type=bool, defval=true)

//Get EMA Values
maA = input(title='MA1 期間', type=integer, minval=1, step=1, defval=10)
maB = input(title='MA2 期間', type=integer, minval=1, step=1, defval=75)
maC = input(title='MA3 期間', type=integer, minval=1, step=1, defval=10)
maD = input(title='MA4 期間', type=integer, minval=1, step=1, defval=20)
maE = input(title='MA5 期間', type=integer, minval=1, step=1, defval=75)
maF = input(title='MA6 期間', type=integer, minval=1, step=1, defval=10)
maG = input(title='MA7 期間', type=integer, minval=1, step=1, defval=75)
maH = input(title='MA8 期間', type=integer, minval=1, step=1, defval=10)

//Set resolutions
resA = input(title='MA1 時間足', type=resolution, defval="15")
resB = input(title='MA2 時間足', type=resolution, defval="15")
resC = input(title='MA3 時間足', type=resolution, defval="60")
resD = input(title='MA4 時間足', type=resolution, defval="60")
resE = input(title='MA5 時間足', type=resolution, defval="60")
resF = input(title='MA6 時間足', type=resolution, defval="240")
resG = input(title='MA7 時間足', type=resolution, defval="240")
resH = input(title='MA8 時間足', type=resolution, defval="1440")

//Set switches
emaAswitch = input(title="MA1 On/Off", type=bool, defval=true)
emaBswitch = input(title="MA2 On/Off", type=bool, defval=true)
emaCswitch = input(title="MA3 On/Off", type=bool, defval=true)
emaDswitch = input(title="MA4 On/Off", type=bool, defval=true)
emaEswitch = input(title="MA5 On/Off", type=bool, defval=true)
emaFswitch = input(title="MA6 On/Off", type=bool, defval=true)
emaGswitch = input(title="MA7 On/Off", type=bool, defval=true)
emaHswitch = input(title="MA8 On/Off", type=bool, defval=true)

//get data
dataA = security(tickerid, resA, SEswitch ? ema(close, maA) : sma(close, maA))
dataB = security(tickerid, resB, SEswitch ? ema(close, maB) : sma(close, maB))
dataC = security(tickerid, resC, SEswitch ? ema(close, maC) : sma(close, maC))
dataD = security(tickerid, resD, SEswitch ? ema(close, maD) : sma(close, maD))
dataE = security(tickerid, resE, SEswitch ? ema(close, maE) : sma(close, maE))
dataF = security(tickerid, resF, SEswitch ? ema(close, maF) : sma(close, maF))
dataG = security(tickerid, resG, SEswitch ? ema(close, maG) : sma(close, maG))
dataH = security(tickerid, resH, SEswitch ? ema(close, maH) : sma(close, maH))


//Plotting
plot(emaAswitch ? dataA : na, color=lime, linewidth=3)
plot(emaBswitch ? dataB : na, color=aqua, linewidth=3)
plot(emaCswitch ? dataC : na, color=orange, linewidth=3)
plot(emaDswitch ? dataD : na, color=yellow, linewidth=3)
plot(emaEswitch ? dataE : na, color=olive, linewidth=3)
plot(emaFswitch ? dataF : na, color=fuchsia, linewidth=3)
plot(emaGswitch ? dataG : na, color=maroon, linewidth=3)
plot(emaHswitch ? dataH : na, color=white, linewidth=4)

study("London_NY", overlay=true)
t1 = time(period, "0900-1700")
t2 = time(period, "1600-2200")
t3 = time(period, "2100-0600")

tokyo = na(t1) ? na : blue
London = na(t2) ? na : white
NY = na(t3) ? na : black

bgcolor(tokyo, title1="tokyo")
bgcolor(London, title2="London")
bgcolor(NY, title3="NY")
  • 0
  • 0
anonymous タイトルなし
Python
//@version=3
study(title="MTF Bollinger Bands", shorttitle="MTF 3 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)
onoffC = input(true, "BB3 ON/OFF")
resC = input(title='BB4時間足 (BB1 Time Frame)', type=resolution, defval="60")
sigmaC = input(3,title='BB3偏差 (BB3 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))
devC = security(tickerid, resC, stdev(close,20))
basisC = security(tickerid, resC, 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
upper_3 = onoffC ? (basisC + devC * sigmaC) : na
lower_3 = onoffC ? (basisC - devC * sigmaC) : na


plot(basisA, color=red,title='BB1 Basis')
plot(basisB, color=orange,title='BB2 Basis')
plot(basisC, color=red,title='BB3 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')
u3 = plot(upper_3, color=purple,title='BB3 Upper')
l3 = plot(lower_3, color=purple,title='BB3 Lower')

fill(u1,l1, color=white, transp=90,title='BB1')
fill(u2,l2, color=white, transp=90,title='BB2')
fill(u3,l3, color=white, transp=90,title='BB3')
  • 0
  • 0
monkukui タイトルなし
TypeScript
/// Questions.vue
<template>
  <div class="pagi-nation">
    <p>curPageId: {{curPageId}}</p>
    <p>totalItemNum: {{totalItemNum}}</p>

    <div v-for="id in questionsList">
      <div class="box">
        <p>title {{id}}</p>
        <p>description {{id}}</p>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Prop, Vue, Emit, Watch} from 'vue-property-decorator';

@Component
export default class PagiNation extends Vue {

  @Prop()
  private curPageId!: number; // 現在のページ番号
  @Prop()
  private totalItemNum!: number; // アイテムの合計数

  private questionsList: number[] = [];
  
  private getQuestionsList(): void {
    this.questionsList = [];
    for(let i: number = 1; i <= 10; i++) {
      this.questionsList.push(i + (this.curPageId - 1) * 10);
    }
  };
  public mounted(): void {
    this.getQuestionsList();
  };

  @Watch('curPageId')
  onCurPageIdChanged(): void {
    this.getQuestionsList();
  }

}
</script>

<style scoped>
.box {
  padding: 0.5em 1em;
  margin: 2em 0;
  font-weight: bold;
  color: #6091d3;/*文字色*/
  background: #FFF;
  border: solid 3px #6091d3;/*線*/
  border-radius: 10px;/*角の丸み*/
}
.box p {
  margin: 0; 
  padding: 0;
}
</style>
  • 0
  • 1
anonymous タイトルなし
Python
  • 0
  • 0
anonymous タイトルなし
PHP
function changeLinkTarget() {
// target="_blank" で、relに noopener か noreferrer がない場合はそれぞれ追加する
echo <<< EOM
<script>
var linkTag = document.getElementsByTagName('a');
for (var i = 0; i < linkTag.length; i++) {
  if (linkTag[i].target == '_blank') {
    var new_rel = linkTag[i].rel;
    if (linkTag[i].rel.match(/noopener/) == null) {
	  new_rel += ' noopener';
	}
	if (linkTag[i].rel.match(/noreferrer/) == null) {
	  new_rel += ' noreferrer';
	}
    linkTag[i].setAttribute('rel', new_rel);
  }
}
</script>
EOM;
}
add_action('wp_footer', 'changeLinkTarget');
  • 0
  • 0
anonymous タイトルなし
PHP
<?php
/**
 * The Header template for our theme
 *
 * Displays all of the <head> section and everything up till <div id="main">
 *
 * @package WordPress
 * @subpackage Twenty_Twelve
 * @since Twenty Twelve 1.0
 */
?><!DOCTYPE html>
<!--[if IE 7]>
<html class="ie ie7" <?php language_attributes(); ?>>
<![endif]-->
<!--[if IE 8]>
<html class="ie ie8" <?php language_attributes(); ?>>
<![endif]-->
<!--[if !(IE 7) & !(IE 8)]><!-->
<html <?php language_attributes(); ?>>
<!--<![endif]-->
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta name="viewport" content="width=device-width" />
<title><?php wp_title( '|', true, 'right' ); ?></title>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="<?php echo esc_url( get_bloginfo( 'pingback_url' ) ); ?>">
<?php // Loads HTML5 JavaScript file to add support for HTML5 elements in older IE versions. ?>
<!--[if lt IE 9]>
<script src="<?php echo get_template_directory_uri(); ?>/js/html5.js" type="text/javascript"></script>
<![endif]-->
<?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>
	
<?php wp_body_open(); ?>
<div id="page" class="hfeed site">
	<header id="masthead" class="site-header" role="banner">
		<hgroup>
			<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
			<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
		</hgroup>

		<nav id="site-navigation" class="main-navigation" role="navigation">
			<button class="menu-toggle"><?php _e( 'Menu', 'twentytwelve' ); ?></button>
			<a class="assistive-text" href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentytwelve' ); ?>"><?php _e( 'Skip to content', 'twentytwelve' ); ?></a>
			<?php
			wp_nav_menu(
				array(
					'theme_location' => 'primary',
					'menu_class'     => 'nav-menu',
				)
			);
			?>
		</nav><!-- #site-navigation -->

		<?php if ( get_header_image() ) : ?>
		<a href="<?php echo esc_url( home_url( '/' ) ); ?>"><img src="<?php header_image(); ?>" class="header-image" width="<?php echo esc_attr( get_custom_header()->width ); ?>" height="<?php echo esc_attr( get_custom_header()->height ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" /></a>
		<?php endif; ?>
	</header><!-- #masthead -->

	<div id="main" class="wrapper">
  • 0
  • 1
anonymous タイトルなし
Java


final public class Pair<T1 extends Comparable<T1>, T2 extends Comparable<T2> > 
	implements Comparable< Pair<T1, T2> > {

	//static fields--------------------------------
	public static final Boolean COMPARE_FIRST = true;
	public static final Boolean COMPARE_SECOND = false;

	//fields--------------------------------
	private final T1 first;
	private final T2 second;
	private final Boolean comparisonValue;

	//methods--------------------------------

	//Constructor
	private Pair(){
		this.first = null;
		this.second = null;
		comparisonValue = true;
	}
	public Pair(T1 v1, T2 v2){
		this(v1, v2, COMPARE_FIRST);
	}
	public Pair(T1 v1, T2 v2, Boolean cmpV){
		this.first = v1;
		this.second = v2;
		this.comparisonValue = cmpV;
	}

	//Getter
	public T1 getFirst(){
		return(this.first);
	}
	public T2 getSecond(){
		return(this.second);
	}

	//ToString
	@Override
	public String toString(){
		String str = "("+this.first+", "+this.second+")";
		return(str);
	}

	//Compare
	@Override
	public int compareTo(Pair<T1, T2> target){
		int result = 0;
		if(this.comparisonValue == COMPARE_FIRST){
			result = (this.first).compareTo(target.first);
			if(result == 0){
				result = (this.second).compareTo(target.second);
			}
		}else{
			result = (this.second).compareTo(target.second);
			if(result == 0){
				result = (this.first).compareTo(target.first);
			}
		}
		return(result);
	}
}
  • 0
  • 1
anonymous タイトルなし
HTML
<p><strong>👇雑談や質問が気軽にできる♪&nbsp;ジャパカジ掲示板</strong></p>
<p>ユーザー同士の交流や雑談、ジャパカジスタッフへの<a href="/forum" title="">お問い合わせ</a>、なんでも大歓迎!</p>
<div><a href="/forum" title=""><img alt="ジャパカジ掲示板はじめました!詳細ページへ" class="full hidden-xs" src="/images/home/images/casino-forum-ad-pc_1502x192.jpg" style="" /><img alt="ジャパカジ掲示板はじめました!詳細ページへ" class="full visible-xs" font-size:10px="" src="/images/home/images/casino-forum-ad-mobile_702x178.jpg" style="" /></a></div>
  • 0
  • 0