alvinalexander.com: Android 5 Preferences tutorial (PreferenceScreen, PreferenceActivity, and PreferenceFragment)

alvinalexander.com: Android 5 Preferences tutorial (PreferenceScreen, PreferenceActivity, and PreferenceFragment)

The code here has been updated from iRomani’s tutorial, and contains the necessary corrections to work with Android 5, specifically using a PreferenceFragment along with the PreferenceActivity:

package com.alvinalexander.preferencestestapp;

import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;

public class MyPreferencesActivity extends PreferenceActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();
    }

    public static class MyPreferenceFragment extends PreferenceFragment
    {
        @Override
        public void onCreate(final Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.preferences);
        }
    }

}
Advertisements

Recurse Center

Recurse Center

Founded in 2011, the Recurse Center is a free, self-directed, educational retreat for people who want to get better at programming, whether they’ve been coding for three decades or three months. Participants come from around the world for 12-week batches in New York, where they write open source software and grow together as programmers in a friendly, intellectual, and energizing environment.

With an alumni network of more than 500 people in dozens of countries, we have one of the most tightly-knit, diverse, and supportive programming communities in the world.

Our retreat is free for everyone, and we offer need-based living-expense grants of up to $7,000 to women and people from groups traditionally underrepresented in programming.

Prior to March of 2015, we were (confusingly) named Hacker School.

The Recurse Center is…

Self-directed

We value intrinsic motivation and self-direction, and believe people learn best when they’re free to explore their passions and interests.

Accessible

We’re free for everyone. We also offer need-based grants for living expenses for people from traditionally underrepresented groups in programming.

Stimulating

We look for smart, friendly, self-directed, and intellectually curious people who enjoy programming and want to get dramatically better.

Exceptional

We have exceptional residents including Peter Norvig, Jessica McKellar, Yaron Minsky, Leigh Honeywell, David Nolen, Peter Seibel, Nada Amin, and more.

Thoughtful

The atmosphere here is friendly and intellectual. We have a gender-balanced environment, and lightweight social rules.

Supportive

We have a tight-knit community of more than 600 alumni from over 25 countries. Our motto is “never graduate.”

Project-based

Recursers have made significant contributions to dozens of open source projects and started many of their own.

Connected

We make money by helping great companies hire our alumni. There’s no obligation to take a job if you don’t want one.

Coz: Finding Code that Counts with Casual Profiling

Coz: Finding Code that Counts with Casual Profiling

By Charlie Cutsinger and Emery Berger

Coz is a new kind of profiler that unlocks optimization opportunities missed by traditional profilers. Coz employs a novel technique we call causal profiling that measures optimization potential. This measurement matches developers’ assumptions about profilers: that optimizing highly-ranked code will have the greatest impact on performance. Causal profiling measures optimization potential for serial, parallel, and asynchronous programs without instrumentation of special handling for library calls and concurrency primitives. Instead, a causal profiler uses performance experiments to predict the effect of optimizations. This allows the profiler to establish causality: “optimizing function X will have effect Y,” exactly the measurement developers had assumed they were getting all along.

Full details of Coz are available in our paper, Coz: Finding Code that Counts with Causal Profiling (pdf), SOSP 2015, October 2015 (recipient of a Best Paper Award).

Requirements

Coz, our prototype causal profiler, runs with unmodified Linux executables. Coz requires:

Python
Clang 3.1 or newer or another compiler with C++11 support
Linux version 2.6.32 or newer (must support the perf_event_open system call)
Building

To build Coz, just clone this repository and run make. The build system will check out other build dependencies and install them locally in the deps directory.

Using Coz

Using coz requires a small amount of setup, but you can jump ahead to the section on the included sample applications in this repository if you want to try coz right away.

To run your program with coz, you will need to build it with debug information. You do not need to include debug symbols in the main executable: coz uses the same procedure as gdb to locate debug information for stripped binaries. If you plan to use your program with progress points (see below), you also need to link your program with the dynamic loader library by specifying the -ldl option.

Once you have your program built with debug information, you can run it with coz using the command coz run {coz options} — {program name and arguments}. But, to produce a useful profile you need to decide which part(s) of the application you want to speed up by specifying one or more progress points.

Profiling Modes

Coz departs from conventional profiling by making it possible to view the effect of optimizations on both throughput and latency. To profile throughput, you must specify a progress point. To profile latency, you must specify a pair of progress points.

Throughput Profiling: Specifying Progress Points

To profile throughput you must indicate a line in the code that corresponds to the end of a unit of work. For example, a progress point could be the point at which a transaction concludes, when a web page finishes rendering, or when a query completes. Coz then measures the rate of visits to each progress point to determine any potential optimization’s effect on throughput.

To place a progress point, include coz.h (under the include directory in this repository) and add the COZ_PROGRESS macro to at least one line you would like to execute more frequently. Don’t forget to link your program with libdl: use the -ldl option.

By default, Coz uses the source file and line number as the name for your progress points. If you use COZ_PROGRESS_NAMED(“name for progress point”) instead, you can provide an informative name for your progress points. This also allows you to mark multiple source locations that correspond to the same progress point.

Latency Profiling: Specifying Progress Points

To profile latency, you must place two progress points that correspond to the start and end of an event of interest, such as when a transaction begins and completes. Simply mark the beginning of a transaction with the COZ_BEGIN(“transaction name”) macro, and the end with the COZ_END(“transaction name”) macro. Unlike regular progress points, you always need to specify a name for your latency progress points. Don’t forget to link your program with libdl: use the -ldl option.

When coz tests a hypothetical optimization it will report the effect of that optimization on the average latency between these two points. Coz can track this information with any knowledge of individual transactions thanks to Little’s Law.

Specifying Progress Points on the Command Line

Coz has command line options to specify progress points when profiling the application instead of modifying its source. This feature is currently disabled because it did not work particularly well. Adding support for better command line-specified progress points is planned in the near future.

Processing Results

To plot profile results, go to http://plasma-umass.github.io/coz/ and load your profile. This page also includes several sample profiles from PARSEC benchmarks.

Sample Applications

The benchmarks directory in this repository includes several small benchmarks with progress points added at appropriate locations. To build and run one of these benchmarks with coz, just browse to benchmarks/{bench name} and type make bench (or make test for a smaller input size). These programs may require several runs before coz has enough measurements to generate a useful profile. Once you have profiled these programs for several minutes, go to http://plasma-umass.github.io/coz/ to load and plot your profile.

wooledge.org: bash Pitfalls

wooledge.org: bash Pitfalls

for i in $(ls *.mp3)
cp $file $target
Filenames with leading dashes
[ $foo = “bar” ]
cd $(dirname “$f”)
[ “$foo” = bar && “$bar” = foo ]
[[ $foo > 7 ]]
grep foo bar | while read -r; do ((count++)); done
if [grep foo myfile]
if [bar=”$foo”]; then …
if [ [ a = b ] && [ c = d ] ]; then …
read $foo
cat file | sed s/foo/bar/ > file
echo $foo
$foo=bar
foo = bar
echo <<EOF
su -c 'some command'
cd /foo; bar
[ bar
== "$foo" ]
for i in {1..10}; do ./something &; done
cmd1 && cmd2 || cmd3
echo "Hello World!"
for arg in $*
function foo()
echo "~"
local varname=$(command)
export foo=~/bar
sed 's/$foo/good bye/'
tr [A-Z] [a-z]
ps ax | grep gedit
printf "$foo"
for i in {1..$n}
if [[ $foo = $bar ]] (depending on intent)
if [[ $foo =~ 'some RE' ]]
[ -n $foo ] or [ -z $foo ]
[[ -e "$broken_symlink" ]] returns 1 even though $broken_symlink exists
ed file <<<"g/d\{0,3\}/s//e/g" fails
expr sub-string fails for "match"
On UTF-8 and Byte-Order Marks (BOM)
content=$(&1 >>logfile
cmd; (( ! $? )) || die
y=$(( array[$x] ))
read num; echo $((num+1))
IFS=, read -ra fields <<< "$csv_line"

pythontips.com: Intermediate Python

pythontips.com: Intermediate Python

1. *args and **kwargs
1.1. Usage of *args
1.2. Usage of **kwargs
1.3. Using *args and **kwargs to call a function
1.4. When to use them?
2. Debugging
3. Generators
3.1. Iterable
3.2. Iterator
3.3. Iteration
3.4. Generators
4. Map & Filter
4.1. Map
4.2. Filter
5. set Data Structure
6. Ternary Operators
7. Decorators
7.1. Everything in python is an object:
7.2. Defining functions within functions:
7.3. Returning functions from within functions:
7.4. Giving a function as an argument to another function:
7.5. Writing your first decorator:
8. Global & Return
8.1. Multiple return values
9. Mutation
10. __slots__ Magic
11. Virtual Environment
12. Collections
12.1. defaultdict
12.2. counter
12.3. deque
12.4. namedtuple
12.5. enum.Enum (Python 3.4+)
13. Enumerate
14. Object introspection
14.1. dir
14.2. type and id
14.3. inspect module
15. Comprehensions
15.1. list comprehensions
15.2. dict comprehensions
15.3. set comprehensions
16. Exceptions
16.1. Handling multiple exceptions:
17. Lambdas
18. One-Liners
19. For – Else
19.1. else clause:
20. Open function
21. Targeting Python 2+3
22. Coroutines
23. Function caching
23.1. Python 3.2+
23.2. Python 2+
24. Context managers
24.1. Implementing Context Manager as a Class:
24.2. Handling exceptions
24.3. Implementing a Context Manager as a Generator

Blog by Dan Luu

Blog by Dan Luu

I started out working on flash memory and optics, and then moved up one level to CPUs. I was lucky enough to land at Centaur, a small company that gave me a lot of freedom, and I ended up doing RTL, ucode, verification, bringup, test, and pretty much everything else you can do on a CPU. After that, I worked on hardware/software co-design to speed up a problem domain for Google. I’m off to start a new job soon, but I’m not big on announcing things in advance, so that’s all I’m going to say about that. If you’re so inclined, you can check out my github, linkedin, and resume, but that just has a bunch of details.