Skip to content

Instantly share code, notes, and snippets.

@aristotle9
aristotle9 / gist:2852355
Created June 1, 2012 13:58 — forked from zythum/gist:2848881
google收录的敏感词
@aristotle9
aristotle9 / zipdb.py
Created June 19, 2012 11:20 — forked from mayli/zipdb.py
Use a zipfile store a dict like k-v database
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# zipdb.py
# Use a zipfile store a dict like k-v database.
# Known bug: duplicate key(filenames) allowed
#
# Copyright 2012 mayli <mayli.he@gmail.com>
#
@aristotle9
aristotle9 / txt2png.hs
Created July 1, 2012 15:31
Trans a txt file to png picture
import Graphics.GD
import System.IO
import Data.Char
import System.Environment
charToColor::Char -> Color
charToColor ch = rgb c c c
where c = ord ch
orderToPosition (width, height) pos = (x, y)
@aristotle9
aristotle9 / conc.hs
Created July 10, 2012 04:35
MVar in Haskell Concurrent
import Control.Concurrent
import Control.Concurrent.MVar
import Control.Monad.Fix (fix)
--seg:: MVar Int -> MVar Int -> Int -> IO ()
seg mself mnext n loop = do
mn <- takeMVar mself
putStrLn $ show mn
putMVar mnext n
loop
@aristotle9
aristotle9 / parse-sol.hs
Created July 18, 2012 08:12
Parse sol data
import qualified Data.ByteString as B
import Data.Binary.Strict.Get
import System.IO
import Text.Printf (printf)
import System.Environment (getArgs)
import Control.Applicative ((<$>))
import Data.Bits ((.|.), (.&.), shiftL, shiftR)
import Data.ByteString.UTF8 (toString)
import Text.JSON.Types
import Text.JSON (encode)
@aristotle9
aristotle9 / Unpacker.java
Last active December 22, 2015 13:59
unpacker for MA pack file, and it's easy to generate pack file, possible to customize MA assets.
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* unpacker for MA pack file
*/
public final class Unpacker {
@aristotle9
aristotle9 / totp.clj
Created January 1, 2014 12:27
Clojure Server of Google Authenticator; Java version: https://github.com/wstrange/GoogleAuth
(ns xxx.totp
(:import org.apache.commons.codec.binary.Base32))
(def ^:const seed "QPA2GEXU3NNZUFKJL3NLZMC5YCA6UGSVDA3TFBJDXCZTQXYGYCYNKKWNU3IQG657CRWNUKNZGA3I2CLBUZYD3K55YZYQ====")
(def ^:const secret-size 10)
(def ^:const random-number-algorithm "SHA1PRNG")
(def ^:const window-size 3)
(defn new-secret
[]
<?php
$a = [
2 => 1,
3 => 1,
4 => 1,
6 => 5,
7 => 5,
8 => 5,
9 => 7,
Failed to parse method: QSizePolicy::QSizePolicy
entity: Entity { kind: Constructor, display_name: Some("QSizePolicy(QSizePolicy::Bits)"), location: Some(SourceLocation { file: Some(File { path: "/usr/local/Cellar/qt/5.9.1/include/QtWidgets/qsizepolicy.h" }), line: 178, column: 38, offset: 7665 }) }
error: Can't parse argument type: b: QSizePolicy::Bits
Failed to parse method: QSizePolicy::Bits::transposed
entity: Entity { kind: Method, display_name: Some("transposed()"), location: Some(SourceLocation { file: Some(File { path: "/usr/local/Cellar/qt/5.9.1/include/QtWidgets/qsizepolicy.h" }), line: 210, column: 14, offset: 8607 }) }
error: Can't parse return type: QSizePolicy::Bits: Type uses private class (QSizePolicy::Bits)
Failed to parse method: QTypeInfo::name
entity: Entity { kind: Method, display_name: Some("name()"), location: Some(SourceLocation { file: Some(File { path: "/usr/local/Cellar/qt/5.9.1/include/QtWidgets/qsizepolicy.h" }), line: 231, column: 1, offset: 9205 }) }
@aristotle9
aristotle9 / binary-search.rs
Last active January 28, 2019 14:15
binary search in ordered list, if not found, return the nearest **left** [(left + right)/2] index.(if need **right** index, use mid = [(left + right + 1) / 2])
const LIST: &[u32] = &[0, 10, 20, 30, 40, 50, 60, 70, 80, 90];
fn search(x: u32) -> usize {
let mut left: usize = 0;
let mut right: usize = LIST.len();
println!("\n\nstart search x({}) in {:?}", x, LIST);
let mut step: u32 = 0;
while true {
let mid = (left + right) / 2;
let val = LIST[mid];