Skip to content

Instantly share code, notes, and snippets.

public void transformPage(View view, float position) {
int pageWidth = view.getWidth();
if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
view.setAlpha(0);
} else if (position <= 1) { // [-1,1]
public class ParallaxPageTransformer implements ViewPager.PageTransformer {
public void transformPage(View view, float position) {
int pageWidth = view.getWidth();
if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
view.setAlpha(1);
/*
* Copyright (C) 2014 Chris Banes
*
* 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
package com.cafesalam.experiments.app.ui;
import org.lucasr.probe.Interceptor;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Point;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
public class CommentsActivity extends ActionBarActivity {
public static final String ARG_DRAWING_START_LOCATION = "arg_drawing_start_location";
@InjectView(R.id.toolbar)
Toolbar toolbar;
@InjectView(R.id.contentRoot)
LinearLayout contentRoot;
@InjectView(R.id.rvComments)
RecyclerView rvComments;
@InjectView(R.id.llAddComment)
AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
try {
// setWiredDeviceConnectionState(int device, int state, String name);
Method method = AudioManager.class.getMethod("setWiredDeviceConnectionState", int.class, int.class, String.class);
method.invoke(audioManager, 4, 0, "headset");
} catch (Exception e) {
e.printStackTrace();
}
/*
这道题的方法就是用在N-Queens中介绍的常见套路。简单地说思路就是循环处理子问题,对于每个格子,带入不同的9个数,然后判合法,如果成立就递归继续,结束后把数字设回空。大家可以看出代码结构和N-Queens是完全一样的。判合法可以用Valid Sudoku做为subroutine,但是其实在这里因为每次进入时已经保证之前的board不会冲突,所以不需要判断整个盘,只需要看当前加入的数字和之前是否冲突就可以,这样可以大大提高运行效率,毕竟判合法在程序中被多次调用。
*/
public class Solution {
public void solveSudoku(char[][] board) {
if(board == null || board.length != 9 || board[0].length != 9)
return;
helper(board, 0, 0);
}
public boolean helper(char[][] board, int i, int j){
@Volcanoscar
Volcanoscar / gist:a0a1f042c6f6f660c407
Last active August 29, 2015 14:26 — forked from saetia/gist:1623487
Clean Install – OS X 10.11 El Capitan Developer Preview 2

OS X Preferences


most of these require logout/restart to take effect

# Enable character repeat on keydown
defaults write -g ApplePressAndHoldEnabled -bool false

# Set a shorter Delay until key repeat
@Volcanoscar
Volcanoscar / AnimationForListView.java
Last active August 29, 2015 14:26 — forked from viizki/AnimationForListView.java
Animation For ListView
private LayoutAnimationController getAnimationController() int duration = 100;
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(duration);
set.addAnimation(animation);
animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, -0.5f, Animation.RELATIVE_TO_SELF, 0.0f);
animation.setDuration(duration);
package main;
public class Main {
private static double getDistanceKm(double lat1, double lon1, double lat2, double lon2){
double latRad1 = lat1 * Math.PI / 180;
double lonRad1 = lon1 * Math.PI / 180;
double latRad2 = lat2 * Math.PI / 180;
double lonRad2 = lon2 * Math.PI / 180;