Skip to content

Instantly share code, notes, and snippets.

View hrkd's full-sized avatar
🎯
Focusing

hrkd

🎯
Focusing
View GitHub Profile
@hrkd
hrkd / the-bind-problem.jsx
Created September 25, 2017 11:36 — forked from Restuta/the-bind-problem.jsx
React, removeEventListener and bind(this) gotcha
/* Sometimes it's pretty easy to run ito troubles with React ES6 components.
Consider the following code: */
class EventStub extends Component {
componentDidMount() {
window.addEventListener('resize', this.onResize.bind(this)); //notice .bind
}
componentWillUnmount() {
window.removeEventListener('resize', this.onResize.bind(this));
#ELBにぶら下がるエンドポイントのIPを取得する
VAR=`aws elb describe-instance-health --load-balancer-name your-elb-name --region your-region | jq -r .InstanceStates[].InstanceId`
echo "${VAR}" | while read line
do
VAR2=`aws ec2 describe-instances --region your-region --instance-ids ${line} | jq -r ".Reservations[].Instances[].PrivateIpAddress"`
#this is IP
@hrkd
hrkd / sketch.pde
Last active August 29, 2015 14:01
import processing.video.*;
Capture capture;
int[] pastPixels;
void setup(){
size(1280, 720);
String[] cameras = Capture.list();
print(cameras[0]);
capture = new Capture(this, cameras[0]);
@hrkd
hrkd / maptag.jsx
Created March 3, 2014 10:37
photoshopの選択範囲から、htmlのmapタグ、areaタグを生成するjsx
// JavaScript Document
var x1 = activeDocument.selection.bounds[0];
var y1 = activeDocument.selection.bounds[1];
var x2 = activeDocument.selection.bounds[2];
var y2 = activeDocument.selection.bounds[3];
var tmp = x1.toString() + y1.toString() + x2.toString() + y2.toString();
var rect = tmp.split(' px');
@hrkd
hrkd / encode_sjis_utf-8.sh
Last active August 29, 2015 13:56
ワンライナーでsjisをutf-8に変換
perl -MEncode -pe 'Encode::from_to($_,"shiftjis","utf-8");' -i.bak text.txt
@hrkd
hrkd / perl_html_entities_decode.sh
Last active August 29, 2015 13:56
ワンライナーでhtmlエンティティをデコード
perl -MHTML::Entities -ple '$_=decode_entities($_)' -i.org text01.txt
@hrkd
hrkd / gist:7688325
Created November 28, 2013 07:15
スペースだけの行を検出
^\s{2,}\n
111111
1111111111
22223323
22323332333
223223332333
22233332222
33333333
2221222
22221221222
@hrkd
hrkd / .htaccess
Last active December 25, 2015 20:29
htaccess関連。小手先ハック感イヤだけど。
#PHPをhtml拡張子で動作・かつSSI有効
AddType application/x-httpd-php .php .html
AddHandler application/x-httpd-php .php .html
AddOutputFilter INCLUDES .html
RewriteEngine On
RewriteBase /
#RewriteCondでURLの条件指定
@hrkd
hrkd / indexOf.js
Last active December 18, 2015 23:49
indexOfを実装していないブラウザ用拡張
if(!Array.indexOf){
Array.prototype.indexOf = function(target,index){
if(isNaN(index)){
index = 0;
}
for(var i = index; i < target.length; i++){
if(this[i] === target){
return i;
}
}