This file contains hidden or 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
import jester, tables, md5 | |
var urls {.threadvar.}: Table[string, string] | |
routes: | |
get "/": | |
if @"url" != "": | |
let id = ($(@"url".toMD5)).substr(0, 5) | |
urls[id] = @"url" | |
resp id |
This file contains hidden or 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 <immintrin.h> | |
#include <stdio.h> | |
unsigned int rnd() { | |
unsigned int r = 0; | |
_rdrand32_step(&r); | |
return r; | |
} |
This file contains hidden or 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 BigDecimal | |
SUFFIX = [['京', 16], ['兆', 12], ['億', 8], ['万', 4]] | |
def convertNumber2JapaneseNumerals | |
number ||= self | |
number_string ||= '' | |
SUFFIX.each do |suffix| | |
if number.exponent >= suffix[1] | |
number_string += number.div(10 ** suffix[1]).to_s + suffix[0] |
This file contains hidden or 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
import Data.List | |
-- http://d.hatena.ne.jp/guccyon/20090510/p1 | |
combn [] n=[] | |
combn lst 1=map (\x -> [x]) lst | |
combn (x:xs) n=[x:y| y <- combn xs (n-1)] ++ combn xs n | |
ss = combn [1..10] 4 | |
ans = [s | sp <- ss, s <- (permutations sp), let x1 = abs(s !! 0 - s !! 1); x2 = abs(s !! 1 - s !! 2); x3 = abs(s !! 2 - s !! 3); x4 = abs(x1 - x2); x5 = abs(x2 - x3); x6 = abs(x4 - x5) in length (nub (x1:x2:x3:x4:x5:x6:s)) == 10] |
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Collections.Specialized; | |
using System.Linq; | |
using System.Net; | |
using System.Security.Cryptography; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication2 |
This file contains hidden or 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
SIGNING_ALGORITHM = 'EG1-HMAC-SHA256' | |
def create_auth_header(method, scheme, host, path, headers, payload = nil, _timestamp = nil, _nonce = nil) | |
timestamp = _timestamp.nil? ? Time.now.gmtime.strftime('%Y%m%dT%H:%M:%S%z') : _timestamp | |
nonce = _nonce.nil? ? UUIDTools::UUID.random_create.to_s : _nonce | |
signing_key = Base64.encode64(OpenSSL::HMAC::digest(OpenSSL::Digest::SHA256.new, @secret, timestamp)).strip | |
authorization_header = SIGNING_ALGORITHM + ' ' | |
authorization_header << "client_token=#{@client_token};" |
This file contains hidden or 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
import java.util.regex.Pattern; | |
public class Temp { | |
public static void main(String[] args) { | |
System.out.println(Pattern.compile("^0$|^0^[0-9]+|^[1-9][0-9]*").matcher("0^1").find()); | |
} | |
} |
This file contains hidden or 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
package questions; | |
public class Questions1_6 { | |
public static void main(String[] args) { | |
// initialize matrix | |
final int N = 10; | |
int[][] matrix = new int[N][N]; | |
for (int i = 0; i < N; i++) { | |
for (int j = 0; j < N; j++) { |
This file contains hidden or 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
public static String deleteDuplicateCharacters(String val) { | |
char[] str = val.toCharArray(); | |
int len = str.length; | |
for (int i = 0; i < len; i++) { | |
for (int j = i + 1; j < len; j++) { | |
if (str[i] == str[j] && str[j] != 0) { | |
for (int k = j; k < len - 1; k++) { | |
str[k] = str[k + 1]; | |
} |
This file contains hidden or 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
public static String deleteDuplicateCharacters(String val) { | |
char[] str = val.toCharArray(); | |
int len = str.length; | |
for (int i = 0; i < len; i++) { | |
for (int j = i + 1; j < len; j++) { | |
if (str[i] == str[j]) { | |
for (int k = j; k < len - 1; k++) { | |
str[k] = str[k + 1]; | |
} |
NewerOlder