Skip to content

Instantly share code, notes, and snippets.

@ruchee
ruchee / 32.asm
Last active August 29, 2015 14:14 — forked from FiloSottile/32.asm
; /usr/local/bin/nasm -f macho 32.asm && ld -macosx_version_min 10.7.0 -o 32 32.o && ./32
global start
section .text
start:
push dword msg.len
push dword msg
push dword 1
mov eax, 4
<?php
public function testSetCookieAction()
{
$value = '12345';
$html = '<html><body>test set cookie varName =' . $value . '</body></html>';
$response = new Response($html);
$response->headers->setCookie(new Cookie('varName', $value, time() + (3600 * 48)));
return $response;
}
@ruchee
ruchee / shell_sort.php
Created November 24, 2014 06:01
希尔排序算法,PHP实现
<?php
// 希排
function shell_sort (&$arr) {
$len = count($arr);
$h = 1;
while ($h < intval($len / 3)) {
$h = 3*$h + 1;
}
@ruchee
ruchee / shell_sort.rb
Created November 24, 2014 06:00
希尔排序算法,Ruby实现
# 希排
class Array
def shell_sort!
len = self.length
h = 1
while h < len / 3
h = 3*h + 1
end
while h >= 1
@ruchee
ruchee / select_sort.php
Created November 24, 2014 02:48
选择排序算法,PHP实现
<?php
// 选排
function select_sort (&$arr) {
$len = count($arr);
for ($i = 0; $i < $len; ++$i) {
$min = $i;
for ($j = $i + 1; $j < $len; ++$j) {
if ($arr[$j] < $arr[$min]) {
$min = $j;
@ruchee
ruchee / select_sort.rb
Created November 24, 2014 02:47
选择排序算法,Ruby实现
# 选排
class Array
def select_sort!
len = self.length
0.upto(len - 1) do |i|
min = i
(i + 1).upto(len - 1) do |j|
min = j if self[j] < self[min]
end
self[i], self[min] = self[min], self[i] if min != i
@ruchee
ruchee / insert_sort.php
Created November 22, 2014 02:22
插入排序算法,PHP实现
<?php
// 插排
function insert_sort (&$arr) {
$len = count($arr);
for ($i = 1; $i < $len; ++$i) {
for ($j = $i; $j >= 1; --$j) {
if ($arr[$j] < $arr[$j - 1]) {
$temp = $arr[$j];
$arr[$j] = $arr[$j - 1];
@ruchee
ruchee / insert_sort.rb
Created November 22, 2014 02:18
插入排序算法,Ruby实现
# 插排
class Array
def insert_sort!
len = self.length
1.upto(len - 1) do |i|
i.downto(1) do |j|
self[j], self[j - 1] = self[j - 1], self[j] if self[j] < self[j -1]
end
end
end
@ruchee
ruchee / binary_search.php
Created November 22, 2014 01:47
二分查找算法,PHP实现
<?php
// 二分
function binary_search ($arr, $key) {
list($lo, $hi) = array(0, count($arr) - 1);
while ($lo <= $hi) {
$mid = intval($lo + ($hi - $lo) / 2);
if ($key < $arr[$mid]) {
$hi = $mid - 1;
} elseif ($key > $arr[$mid]) {
@ruchee
ruchee / binary_search.rb
Created November 22, 2014 01:32
二分查找算法,Ruby实现
# 二分
class Array
def binary_search (key)
lo, hi = 0, self.length - 1
while lo <= hi
mid = lo + (hi - lo) / 2
hi = mid - 1 if key < self[mid]
lo = mid + 1 if key > self[mid]
return mid if key == self[mid]
end