Skip to content

Instantly share code, notes, and snippets.

View stanwu's full-sized avatar

Stan Ht. Wu stanwu

View GitHub Profile
@stanwu
stanwu / getMacAddress.java
Created May 22, 2013 06:49
android get mac address
WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo info = manager.getConnectionInfo();
String address = info.getMacAddress());
@stanwu
stanwu / gist:6232367
Created August 14, 2013 15:50
這應該算是骨灰級的老問題了 int i = 1; if ( i == 1 ) printf ("yes"); else printf ("no"); PS: 可彈性調整 i 裡面的值 0-65535 如果改寫成 完全拋棄不使用 if 或是 ? : 之類的判斷式, 有其他寫法可以得到一樣的結果嗎?
#include <stdio.h>
void main() {
char *ans[4]={"yes","no","no","no"};
int i=1;
int idx;
idx=abs((32767-65535/(i+1))/10000);
printf("i=%i, idx=%i, ans=%s\n", i, idx, ans[idx]);
@stanwu
stanwu / gist:6915310
Last active December 25, 2015 04:09
get android app widgets list
package com.example.test;
import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.appwidget.AppWidgetHost;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
import android.content.Intent;
@stanwu
stanwu / AppWidgetHost.java
Created October 12, 2013 08:25
AppWidgetHost
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@stanwu
stanwu / rotate.sh
Created November 5, 2013 04:17
keep last 60 backup files
#!/bin/bash
keep_part=`ls -tr *.tgz | tail -n 60`
for i in `ls *.tgz`
do
is_found=`echo $keep_part | grep $i`
if [ -z "$is_found" ]; then
echo "purge $i"
rm -f $i
else
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
// $("button").click(function(){
$.get("http://xxxxxx/api/1.0/xxxx/",function(data,status){
var obj = jQuery.parseJSON(data);
#!/usr/bin/python
"""
get free sits from API call
python example by stanwu
"""
import urllib2
import json
response = urllib2.urlopen('http://xxxx.xxxxx.xxx/')
/*
* Copyright (c) 2013 Calvin Rien
*
* Based on the JSON parser by Patrick van Bergen
* http://techblog.procurios.nl/k/618/news/view/14605/14863/How-do-I-write-my-own-parser-for-JSON.html
*
* Simplified it so that it doesn't throw exceptions
* and can be used in Unity iPhone with maximum code stripping.
*
* Permission is hereby granted, free of charge, to any person obtaining
@stanwu
stanwu / miniupnpc.sh
Created January 23, 2014 12:29
build miniupnpc-static for ARM7
#!/bin/bash
export CC=/opt/arm-2010.09/bin/arm-none-linux-gnueabi-gcc
make
alias updatedb="updatedb --localpaths='/cygdrive/c'"
alias df="df -h"
alias du="du -h"
alias locate="locate -i"