Skip to content

Instantly share code, notes, and snippets.

View samma835's full-sized avatar

samma samma835

  • Shanghai
View GitHub Profile
@samma835
samma835 / slide_in_up.xml
Created October 22, 2012 07:31
animation of android(ep.ImageSwitcher)
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromYDelta="-50%p"
android:toYDelta="0" />
<alpha
android:duration="500"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
</set>
@samma835
samma835 / get_constellation.php
Created October 29, 2012 13:48
根据日期获取星座
// $birthday的格式为yyyy-mm-dd
public function getConstellation($birthday, $format=null)
{
$pattern = '/^\d{4}-\d{1,2}-\d{1,2}$/';
if (!preg_match($pattern, $birthday, $matchs))
{
return null;
}
$date = explode('-', $birthday);
@samma835
samma835 / SearchSuggestions.java
Created November 14, 2012 09:25
文本框中的搜索建议
@Override
public boolean onQueryTextChange(String searchText) {
// 清空上一次的搜索结果
GlobalInfo.searchGameResults.clear();
// 取得搜索结果集
int resultCount = 0;
for (HashMap<String, String> item : GlobalInfo.searchGameSet) {
if (item.get("game_name").contains(searchText)) {
resultCount++;
@samma835
samma835 / SetDrawableWithDensity.java
Created November 19, 2012 09:46
代码中设置Drawable时,按屏幕Density等比例缩放
bd = new BitmapDrawable(tmpInfo.bitmap);
try {
Method m = BitmapDrawable.class.getMethod(
"setTargetDensity",
new Class[] { DisplayMetrics.class });
m.invoke(bd, GlobalInfo.currentActivity.getResources()
.getDisplayMetrics());
} catch (NoSuchMethodException e) {
e.printStackTrace();
@samma835
samma835 / shuffle.c
Created November 20, 2012 05:20
Fisher和Yates的洗牌算法
void ShuffleArray_Fisher_Yates(char* arr, int len)
{
int i = len, j;
char temp;
if ( i == 0 ) return;
while ( --i ) {
j = rand() % (i+1);
temp = arr[i];
arr[i] = arr[j];
@samma835
samma835 / search_domain.py
Created November 27, 2012 01:01 — forked from lintianzhi/search_domain.py
search availible domain name
#!/usr/bin/python
#coding=utf-8
import urllib
import urllib2
import re
import threading
import Queue
url = 'https://who.is/whois/name_search/'
@samma835
samma835 / share.js
Created December 1, 2012 00:24
分享到朋友圈及其他
// 发送给好友;
WeixinJSBridge.on('menu:share:appmessage', function(argv){
WeixinJSBridge.invoke('sendAppMessage',{
"appid":appId,
"img_url":imgUrl,
"img_width":"640",
"img_height":"640",
"link":"http://yige.org/php/",
"desc":"一个网在线教程",
"title":"yige.org"
@samma835
samma835 / add.js
Created December 1, 2012 00:26
微信恶俗关注
var addWxContact = function(wxid, cb)
{
if (typeof WeixinJSBridge == 'undefined') return false;
WeixinJSBridge.invoke('addContact', {
webtype: '1',
username: wxid
}, function(d) {
// 返回d.err_msg取值,d还有一个属性是err_desc
// add_contact:cancel 用户取消
// add_contact:fail 关注失败
@samma835
samma835 / SAE_Location.php
Created December 6, 2012 03:20
SAE地理信息服务
<?php
$api = new apibus(); //创建 ApiBus 对象
$Geo = $api->load( "geoone"); //创建一级地理位置服务对象
// getDriveRoute方法 测试通过
$begin = "121.418687,31.21855";
$end = "121.400263,31.23210";
$drive_route = $Geo->getDriveRoute($begin, $end);
echo "drive_rote: ";
print_r($drive_route);
@samma835
samma835 / LogMemory.java
Created April 27, 2013 07:17
function to log the memory status.
private void logMemory(String callingFunction)
{
long max = Runtime.getRuntime().maxMemory() / 1024;
if (debugJavaMemory)
{
long used = Runtime.getRuntime().totalMemory() / 1024;
long available = max - used;
long change = available - availableJavaMemoryOld;
if (availableJavaMemoryOld != 0)