o9s
is a microblog
home archives search feed blogroll


Page 2 of 33

Shortfizz

My 65 characters fizzbuzz implementation. It’s not the prettiest, but it checks all the boxes.

for(i=0;i<101;i++)console.log((i%3?'':'Fizz')+(i%5?'':'Buzz')||i)
Posted on 2018-05-23   #javascript  


Toggle Soft Keyboard In iOS Emulators

cmd+K

How did I not know that? I always tested the keyboard showing up and dismissing properly with a real device.

Posted on 2018-05-09   #ios  


Vowel Counter

<o9>  replace any letter that is not a vowel with an
      empty string and get the length of the string
<MSC> str.replace(/[^aeiou]/ig,"").length;
Posted on 2018-05-08   #javascript     #oneliner  


Exiting Vim

Exiting Vim

Posted on 2018-05-07   #vim  


ShowMoreTextView

/**
 * A text view with a 'More...' button when the text is too long.
 */

public class ShowMoreTextView extends AppCompatTextView {

    private static final int TEXT_MAX_LENGTH = 200;

    public ShowMoreTextView(Context context) {
        super(context);
        setMovementMethod(LinkMovementMethod.getInstance());
    }

    public ShowMoreTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setMovementMethod(LinkMovementMethod.getInstance());
    }

    public ShowMoreTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setMovementMethod(LinkMovementMethod.getInstance());
    }

    public void setShortened(final CharSequence sequence) {
        if (sequence != null &amp;&amp; sequence.length() > TEXT_MAX_LENGTH) {
            CharSequence text = sequence.subSequence(0, TEXT_MAX_LENGTH - 3) + "... ";
            String more = getContext().getString(R.string.more);
            SpannableString ss = new SpannableString(text + more);

            ss.setSpan(new ClickableSpan() {
                @Override
                public void onClick(View textView) {
                    setFullened(sequence);
                }
            }, ss.length() - more.length(), ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

            setText(ss);
        } else {
            setText(sequence);
        }
    }

    private void setFullened(final CharSequence sequence) {
        String less = getContext().getString(R.string.less);
        SpannableString ss = new SpannableString(sequence + " " + less);

        ss.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View textView) {
                setShortened(sequence);
            }
        }, ss.length() - less.length(), ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        setText(ss);
    }

}

Don’t forget to add more’ and less’ to strings.xml.

Posted on 2018-04-25   #android     #java  


← Newer posts         Next page →
Page 2 of 33