Skip to content

Instantly share code, notes, and snippets.

<?php
# http://darklaunch.com/2009/08/07/base58-encode-and-decode-using-php-with-example-base58-encode-base58-decode
#################################################################
function base58_encode($num) {
$alphabet = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
$base_count = strlen($alphabet);
$encoded = '';
@c93614
c93614 / searchd
Created August 21, 2013 00:09
sphinx searchd init.d script
#!/bin/sh
#
# sphinx searchd Free open-source SQL full-text search engine
#
# chkconfig: - 20 80
# description: Starts and stops the sphinx searchd daemon that handles \
# all search requests.
### BEGIN INIT INFO
# Provides: searchd
<?php
class base58
{
static public $alphabet = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
public static function encode($int) {
$base58_string = "";
$base = strlen(self::$alphabet);
while($int >= $base) {
# -*- coding=utf-8 -*-
# 修改了原gist里space tab混乱的情况
import feedparser
import re
import collections
import math
def info_entropy(words):
result = 0
total = sum([val for _, val in words.iteritems()])
@c93614
c93614 / apc.php
Last active December 17, 2015 10:49
A more easy way to count online users using php + apc/memcached or redis
<?php
session_start();
// ref: http://expressjs.com/guide.html#users-online
function get_online_user($session_id) {
if (false === ($online_users = apc_fetch("online/users"))) {
$online_users = [];
}
$online_users[$session_id] = time();
These weights are often combined into a tf-idf value, simply by multiplying them together. The best scoring words under tf-idf are uncommon ones which are repeated many times in the text, which lead early web search engines to be vulnerable to pages being stuffed with repeated terms to trick the search engines into ranking them highly for those keywords. For that reason, more complex weighting schemes are generally used, but tf-idf is still a good first step, especially for systems where no one is trying to game the system.
There are a lot of variations on the basic tf-idf idea, but a straightforward implementation might look like:
<?php
$tfidf = $term_frequency * // tf
log( $total_document_count / $documents_with_term, 2); // idf
?>
It's worth repeating that the IDF is the total document count over the count of the ones containing the term. So, if there were 50 documents in the collection, and two of them contained the term in question, the IDF would be 50/2 = 25. To be accurate, we s
func callA() string {
time.Sleep(time.Millisecond * 300)
return "Hello A"
}
func callB() string {
time.Sleep(time.Millisecond * 100)
return "Hello B"
}
@c93614
c93614 / git_guidline.md
Created October 16, 2012 06:26 — forked from onlytiancai/git_guidline.md
git分支使用规范

分支管理

最少有三个长期分支

  • master: 用于生产环境部署
  • testing: 用于测试环境测试
  • dev: 用于日常开发

有一些临时分支

@c93614
c93614 / gist:3848993
Created October 7, 2012 17:23 — forked from observerss/gist:3798922
Google Keyword Tool Scraper(casperjs version)
// requires
var utils = require('utils');
var casper = require('casper').create()
var casper = require('casper').create({
verbose: true,
logLevel: "debug"
});
// setup globals
var email = casper.cli.options['email'] || 'REPLACE THIS EMAIL';
@c93614
c93614 / gist:3187794
Created July 27, 2012 12:55 — forked from 1999/gist:2602021
AWS SES php example
<?php
date_default_timezone_set( 'Europe/Moscow' );
ini_set( 'memory_limit', '1024M' );
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, 'https://email.us-east-1.amazonaws.com' );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_HEADER, true );