Skip to content

Instantly share code, notes, and snippets.

class Array
def insert_and_delete(idx, y)
move_elem = self[idx]
self.delete_at(idx)
self.insert(y, move_elem)
end
end
def insert_sort(arr)
num_of = arr.size - 1
ary = [10, 5, 3, 4, 20, 50, 15]
#配列を受けて二つに割る。
def split_ary(ary, pivot_idx = 0)
left = []
right = []
pivot = 0
ary.each_with_index do |val, index|
next if index == pivot_idx
if val < ary[pivot_idx]
ary = [10, 5, 3, 4, 20, 50, 15]
#配列を受けて二つに割る。
def split_ary(ary, pivot_idx = 0)
return ary if ary.empty?
left = []
right = []
ary.each_with_index do |val, index|
next if index == pivot_idx
if val < ary[pivot_idx]
module A
hoge = "hoge"
module B
fuga = "fuga"
def self.b
p hoge
end
def self.c
p fuga
@littlekbt
littlekbt / scope.rb
Last active December 18, 2015 05:27
def dubble(a)
if a.is_a?(Fixnum)
result = a * 2
end
p result
end
def index(idx, arr)
# 終了条件
return p arr[0] if idx == 0
# 頭1つ落とす
index idx - 1, arr[1..-1]
end
index 3, [1, 2, 3, 4, 5]
articles_table = Article.arel_table
# subquery
articles = articles_table
.project(Arel.star) # project = select
.where(articles_table[:type].eq('daily'))
.or(articles_table[:type].eq('weekly')) # or
.and(articles_table[:type].not_eq('monthly')) #!=
.and(articles_table[:active].eq(1)) # =
.and(articles_table[:created_at].gt(Date.today)) # >
var https = require("https");
exports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));
// テキストが送られた時
var msg = event.entry[0].messaging[0].message.text;
console.log(msg);
// 画像が送られた時
// console.log(event.entry[0].messaging[0].message.attachments[0].payload.url);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<input type="button" id="decr" name="name" value="-">
<span id="num"></span>
<input type="button" id="incr" name="name" value="+">
(function( $ ){
$.fn.incr = function() {
return this.html(parseInt(this.html()) + 1);
};
$.fn.decr = function() {
return this.html(parseInt(this.html()) - 1);
};
})( jQuery );