Skip to content

Instantly share code, notes, and snippets.

View songzhiyong's full-sized avatar
🌍

Jerome Song songzhiyong

🌍
View GitHub Profile
@songzhiyong
songzhiyong / PHP-getIp
Last active December 27, 2015 18:09
PHP getIp method
function getIp() {
if (getenv ( "HTTP_CLIENT_IP" ) && strcasecmp ( getenv ( "HTTP_CLIENT_IP" ), "unknown" )) {
$ip = getenv ( "HTTP_CLIENT_IP" );
} else if (getenv ( "HTTP_X_FORWARDED_FOR" ) && strcasecmp ( getenv ( "HTTP_X_FORWARDED_FOR" ), "unknown" )) {
$ip = getenv ( "HTTP_X_FORWARDED_FOR" );
} else if (getenv ( "REMOTE_ADDR" ) && strcasecmp ( getenv ( "REMOTE_ADDR" ), "unknown" )) {
$ip = getenv ( "REMOTE_ADDR" );
} else if (isset ( $_SERVER ['REMOTE_ADDR'] ) && $_SERVER ['REMOTE_ADDR'] && strcasecmp ( $_SERVER ['REMOTE_ADDR'], "unknown" )) {
$ip = $_SERVER ['REMOTE_ADDR'];
} else {
@songzhiyong
songzhiyong / OC-Date
Last active December 27, 2015 22:29
IOS datePicker
NSDate *selected = [_datePicker date];
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate: selected];
NSDate *localeDate = [selected dateByAddingTimeInterval: interval];
body {
background:#e2b29f;
font-size:120%;
}
.rabbit {
width:5em;
height:3em;
background:#ffffff;
border-radius:70% 90% 60% 50%;
@songzhiyong
songzhiyong / Rabbit-by-Beard-Chicken.markdown
Created November 21, 2013 05:40
A Pen by Katy DeCorah.
@songzhiyong
songzhiyong / JS-reg
Created November 28, 2013 09:23
6-20字符 javascript
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type='text/javascript'>
var reg=/^[\w\_\-]{6,20}$/;
alert(reg.test("12345"));
alert(reg.test("12345+"));
alert(reg.test("12345a-_"));
</script>
package net.jthoenes.blog.spike.lambda;
import java.util.Arrays;
import java.util.List;
public class LambdaIntro {
public static interface ItemWithIndexVisitor<E> {
public void visit(E item, int index);
<style name="MyTheme" parent="@android:style/Theme.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:windowAnimationStyle">@style/MyAnimation.Window</item>
</style>
<!-- Animations -->
<style name="MyAnimation" />
<!-- Animations for a non-full-screen window or activity. -->
<style name="MyAnimation.Window" parent="@android:style/Animation">
@songzhiyong
songzhiyong / Android-ShareCompat
Created December 9, 2013 06:32
Android 利用ShareCompat Build模式分享内容
//分享文本
ShareCompat.IntentBuilder.from(this)
.setType("text/plain")
.setText("I'm sharing!")
.startChooser();
//分享单个文件
ShareCompat.IntentBuilder.from(this)
.setType("text/plain")
.setStream(Uri.parse(SharingSupportProvider.CONTENT_URI + "/foo.txt"))
.startChooser();
@songzhiyong
songzhiyong / Android-App details
Created December 22, 2013 13:58
How to show details for installed application on Android?
Intent intent;
if (android.os.Build.VERSION.SDK_INT >= 9) {
/* on 2.3 and newer, use APPLICATION_DETAILS_SETTINGS with proper URI */
Uri packageURI = Uri.parse("package:" + pkgName);
intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS", packageURI);
ctx.startActivity(intent);
} else {
/* on older Androids, use trick to show app details */
intent = new Intent(Intent.ACTION_VIEW);