Skip to content

Instantly share code, notes, and snippets.

@fukajun
fukajun / App.js
Last active August 29, 2015 14:25
import React from 'react'
export class Appp extends React.Component{
constructor(props) {
super(props)
this.state = {
counter: 0
}
}
change(e) {
console.log(e.target.value)

Nailing that validation with React JS

Validation is complex. Validation is extremely complex. I think it is right up there at the top of implementations we misjudge regarding complexity. So why is validation so difficult in general? How could we implement this with React JS? And do you get a prize for reading through this article? ... yep, you do! Look forward to a virtual cookie at the bottom of this article, you will definitely deserve it ;-)

At my employer, Gloppen EDB Lag, we are building a React JS component framework for application development. We have everything from grids and panels to calendars and forms. Think of it as React Bootstrap, but with bigger parts specific to our applications. So we have lots of forms in our applications and we needed a form that could handle both user input validation, server validation and be very flexible with the contents of the form.

This article will explain the challenges and the thought process of building such a form component. Forms and validation is comple

@fukajun
fukajun / gist:81397a29fedbf5dccb4c
Created June 29, 2015 14:24
コードをコピーしてコメント付きのMarkdownをレジスタに登録する
function! Memo() range
let tmp = @@
silent normal gvy
let selected = @@
let @@ = tmp
let line = line('.')
let memo = input('memo: ')
let fpath = expand('%:p')
let buf = ''
@fukajun
fukajun / gist:edea3c4f36e37bf36e8b
Last active February 19, 2017 14:28
pecoでgit logから指定したコミットのハッシュを取るコマンド
git log --graph --pretty=format:'%d %an: %s %ar %h' | peco | awk -F ' ' '{ print $NF }'
@fukajun
fukajun / demo_app_call_stack.txt
Created April 28, 2015 15:40
demo_app_call_stack
/Users/fukajun/Dropbox/fukajun/src/github.com/fukajun/demo_app/app/controllers/posts_controller.rb:8:in `index'
/Users/fukajun/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/actionpack-4.1.9/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
/Users/fukajun/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/actionpack-4.1.9/lib/abstract_controller/base.rb:189:in `process_action'
/Users/fukajun/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/actionpack-4.1.9/lib/action_controller/metal/rendering.rb:10:in `process_action'
/Users/fukajun/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/actionpack-4.1.9/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
/Users/fukajun/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/activesupport-4.1.9/lib/active_support/callbacks.rb:113:in `call'
/Users/fukajun/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/activesupport-4.1.9/lib/active_support/callbacks.rb:113:in `call'
/Users/fukajun/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/activesupport-4.1.9/lib
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style type="text/css">
@import url(http://fonts.googleapis.com/css?family=Noto+Sans);
body {
font-family: 'VL Gothic';
}

fukajun

@fukajun 関西出身

rails

  • しゃくなげ

github

@fukajun
fukajun / formCopy.js
Created December 29, 2014 08:57
フォームの内容をコピーするスクリプト
// コピー(コピーしたいフォームの値をlocalstrageへ)
var data = {};
$('form input[type!=hidden], form textarea').each(function(i, el){
data[el.id] = $(el).val();
})
localStorage.setItem("form-data",JSON.stringify(data));
// ペースト(localstrageから取り出して入力)
var restore = JSON.parse(localStorage.getItem("form-data"));
for(var i in restore) {
<html>
<body>
</body>
<script>
function num(px) {
return Number(px.replace('px', ''))
}
function px(num) {
return num + "px";
}
@fukajun
fukajun / calc_for_table.rb
Last active August 29, 2015 14:07
テーブルを自作するときの角度のある脚の設置位置を計算
# 家のテーブルを作成するときの
# 脚の設置位置を計算するためのスクリプト
# 変わりそうな値は定数にしてる
module Math
def self.radians(degree)
degree * Math::PI / 180
end
end
#