This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# for C(3, 1) it should returns %w(100 010 001) | |
def get_combinations (n, m) | |
(n.downto 1).to_a.combination(m).map do |c| | |
c.inject(0){ |s, k| s |= (1 << k-1) }.to_s(2).rjust(n, '0') | |
end | |
end | |
puts get_combinations(10, 5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
require 'RMagick' | |
include Magick | |
image = Image.read("image.png").first | |
text = Draw.new | |
text.annotate(image, 0, 0, 0, 60, "測試!Test!") { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- encoding: utf8 | |
# sudo easy_install PIL | |
import Image | |
import ImageFont | |
import ImageDraw | |
image = Image.open("image.png") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Kirsch | |
require 'RMagick' | |
include Magick | |
@@kernel = [ | |
5, 5, -3, 5, 0, -3, -3, -3, -3, | |
5, 5, 5, -3, 0, -3, -3, -3, -3, | |
-3, 5, 5, -3, 0, 5, -3, -3, -3, | |
-3, -3, 5, -3, 0, 5, -3, -3, 5, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Sobel | |
require 'RMagick' | |
include Magick | |
@@kernels = { | |
:up => [1, 2, 1, 0, 0, 0, -1, -2, -1], | |
:down => [-1, -2, -1, 0, 0, 0, 1, 2, 1], | |
:left => [1, 0, -1, 2, 0, -2, 1, 0, -1], | |
:right => [-1, 0, 1, -2, 0, 2, -1, 0, 1] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <security/pam_modules.h> | |
#include <security/pam_appl.h> | |
#include <sys/types.h> | |
#include <gcrypt.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <time.h> | |
#define SERVER_SECRET "MY_SECRET" | |
void gen_otp (char **otp) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 引入 Win32 API 中的 User32.DLL | |
* 需要加上 using System.Runtime.InteropServices; | |
*/ | |
[DllImport("user32.dll")] | |
public static extern Boolean GetWindowRect(IntPtr hWnd, ref Rectangle bounds); | |
public void CaptureWindow () { | |
/* 取得目標視窗的 Handle | |
* 需要加上 using System.Diagnostics; | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% uuid = (rand * 1e10).floor %> | |
<script type="text/javascript"> | |
var timer; | |
var elapsed; | |
function update_progress() { | |
elapsed += 1; | |
jQuery.ajax({ | |
type: "GET", | |
url: "/progress", | |
dataType: "json", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// copyed from "iPhone Developer's Cookbook", Addison-Wesley 2009 | |
#import <UIKit/UIKit.h> | |
@interface HelloWorldViewController : UIViewController | |
@end | |
@implementation HelloWorldViewController | |
- (void) loadView | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'net/http' | |
require 'uri' | |
if ARGV.length < 1 then | |
puts "Usage: ./paste2plurk.rb [filename] ... " | |
exit | |
end | |
def get_language (filename) |