Skip to content

Instantly share code, notes, and snippets.

View Shinpeim's full-sized avatar

Shinpei Maruyama Shinpeim

View GitHub Profile
class Nyan
self.instance_eval do
def nyan
p 'nyan'
end
end
end
Nyan.nyan # => 'nyan'
package main
import (
"fmt"
)
type TailByteReader struct {
}
func (r *TailByteReader) ReadByte() (c byte, e error) {
function Person(firstName, lastName){
this.firstName = firstName;
this.lastName = lastName;
}
Person.prototype.greet = function(){
alert("hello! I'm " + this.firstName + " " + this.lastName);
}
var p = new Person("shinpei", "maruyama");
<?php
// chords テーブル
// id integer
// root varchar
// quality varchar
//
// rootには C, C#, D, D#, E....が入る
// quality テーブルにはm,Mが入る
// このテーブルには、12音 * 2つのqualityで24個のデータを最初から入れておく
// たとえばこんなかんじ
int nyan(){
int *p1 = (int *)malloc(sizeof(int))
int *p2 = (int *)malloc(sizeof(int))
int *p3 = (int *)malloc(sizeof(int))
int retval = 0;
// ごちゃごちゃなんかやる
//!エラーが起こった!
#include <stdio.h>
int main(int argc, char *argv[]){
long l = strtol("string");
int strtol_err = errno; // コピーしとかないといけない
// ちょっとなんかやる間にerrnoが書きかわる可能性‥‥
if (strtol_err== EINVAL) {
// エラー処理
} else if (strtol_err == ERANGE) {
#include <stdio.h>
int main(int argc, char *argv[]){
long l = strtol("string");
// なんかこうごちゃごちゃといろいろやる
some_function(l); // ここでおかしなことになる
return 0;
}
function Person(firstName, lastName){
this.firstName = firstName;
this.lastName = lastName;
}
var p = new Person("shinpei", "maruyama");
function nyan(p){
p = new Person("tarou", "yamada");
}
var array = [1, 2, 3];
function reAssign(a) {
// aに再代入
a = [];
}
reAssign(array);
// reAssignの中の a と 外のarrayは「別の変数」だから
// aにほかのものを代入してもarrayには影響がない。
console.log(array); // [1, 2, 3]
// さらに、notesの初期化はコンストラクタでやれば
// if 文が減らせて、複雑性が減り、バグを入れ込みにくくなる
function Key(){
// snip
this.notes = [];
// snip
}
Key.prototype.renderTo = function(cssId) {
for(var i=0; i < this.notes.length; i++){
var selector = cssId + " ." + this.notes[i];