Skip to content

Instantly share code, notes, and snippets.

View run26kimo's full-sized avatar
👋
Hello ~

RichKe run26kimo

👋
Hello ~
  • Taipei, Taiwan
View GitHub Profile
# Optimized for writes, sort on read
# LVC
redis.hset("bonds|1", "bid_price", 96.01)
redis.hset("bonds|1", "ask_price", 97.53)
redis.hset("bonds|2", "bid_price", 95.50)
redis.hset("bonds|2", "ask_price", 98.25)
redis.sadd("bond_ids", 1)
redis.sadd("bond_ids", 2)
# in controller
# for local files
send_file '/path/to/file', :type => 'image/jpeg', :disposition => 'attachment'
# for remote files
require 'open-uri'
url = 'http://someserver.com/path/../filename.jpg'
data = open(url).read
send_data data, :disposition => 'attachment', :filename=>"photo.jpg"
@run26kimo
run26kimo / search.html
Created March 8, 2012 06:44
fg search new autocomplete
<!--註解-->
<!-- <link rel="stylesheet" type="text/css" href="http://www.fashionguide.com.tw/jquery.autocomplete.css" /> -->
<!-- <script src="http://www.fashionguide.com.tw/js/jquery-1.6.2.min.js" type="text/javascript"></script> -->
<!-- <script src="http://www.fashionguide.com.tw/js/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script> -->
<!-- <script src="http://www.fashionguide.com.tw/js/jquery.autocomplete.min.js" type="text/javascript"></script> -->
<!--加入新的 jquery -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.8.18/jquery-ui.min.js" type="text/javascript"></script>
@run26kimo
run26kimo / php_des_ecb_encrypt
Created April 18, 2012 01:47
php_des_ecb_encrypt
function encrypt($str, $key)
{
$block = mcrypt_get_block_size('des', 'ecb');
$pad = $block - (strlen($str) % $block);
$str .= str_repeat(chr($pad), $pad);
return base64_encode(mcrypt_encrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB));
}
@run26kimo
run26kimo / mcrypt_ecb
Created April 19, 2012 02:34
mcrypt_ecb
<?php
$key = "admlX71MbBLlEznv";
$text = "fleshwound is a farmer,deadly wounded ";//明文
$ctext = base64_encode (mcrypt_ecb (MCRYPT_3DES, $key, $text, MCRYPT_ENCRYPT) ); //加密
$ptext = mcrypt_ecb (MCRYPT_3DES, $key,base64_decode($ctext), MCRYPT_DECRYPT); //解密
echo "明文:$text <br> 密文:$ctext <br>解密后明文:$ptext"
@run26kimo
run26kimo / controller.rb
Created August 27, 2012 06:06 — forked from joakimk/controller.rb
A way to lazy load partials in Rails 3
class Controller
include LazyLoad
def show
@model = Model.find(...)
respond_to do |format|
format.html do
@html_specific_data = Model.find(...)
end
@run26kimo
run26kimo / youtube.html
Created March 6, 2013 04:04
iframe 嵌入 Youtube auto play 自動播放 & mute 靜音
<iframe class="youtube-player" id="player" type="text/html" src="http://www.youtube.com/embed/EnErifh93hM?autoplay=1" height="400px" width="600px"></iframe>
<!-- 1. The <div> tag will contain the <iframe> (and video player) -->
<div id="player"></div>
<script> // 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
@run26kimo
run26kimo / iframe_youtube_mute.html
Created March 6, 2013 04:01
iframe 嵌入 Youtube 自動播放 , 靜音
<iframe class="youtube-player" id="player" type="text/html" src="http://www.youtube.com/embed/EnErifh93hM?autoplay=1" height="600px" width="400px"></iframe>
<!-- 1. The <div> tag will contain the <iframe> (and video player) -->
<div id="player"></div>
<script> // 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
@run26kimo
run26kimo / youtube.html
Created March 6, 2013 04:04
iframe 嵌入 Youtube auto play 自動播放 & mute 靜音
<iframe class="youtube-player" id="player" type="text/html" src="http://www.youtube.com/embed/EnErifh93hM?autoplay=1" height="400px" width="600px"></iframe>
<!-- 1. The <div> tag will contain the <iframe> (and video player) -->
<div id="player"></div>
<script> // 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
<script type="text/javascript" src="http://run26kimo.github.io/we-are-g0v/FileSaver.js"></script>
<script type="text/javascript" src="http://run26kimo.github.io/we-are-g0v/filer.min.js"></script>
<script type="text/javascript">
function download(){
blob = Util.dataURLToBlob(getBase64());
saveAs(blob,'cover.png')
}
</script>