Skip to content

Instantly share code, notes, and snippets.

View booknara's full-sized avatar

Daehee Han booknara

  • Facebook.Inc
  • San Jose, CA
View GitHub Profile
@booknara
booknara / HappyNumber.java
Created April 22, 2016 00:00
Checking Happy number
import java.util.HashSet;
import java.util.Set;
/**
* Happy number (https://en.wikipedia.org/wiki/Happy_number) : A happy number is a number defined by the following process:
* Starting with any positive integer, replace the number by the sum of the squares of its digits,
* and repeat the process until the number either equals 1 (where it will stay),
* or it loops endlessly in a cycle which does not include 1.
* Those numbers for which this process ends in 1 are happy numbers,
* while those that do not end in 1 are unhappy numbers (or sad numbers).
@booknara
booknara / Power3.java
Created April 21, 2016 22:58
Checking the number of power 3
/**
* Created by Daehee Han(@daniel_booknara) on 4/21/16.
*/
public class Power3 {
public static void main(String[] args) {
for (int i = 1; i < 1000; i++) {
if (isPower3(i))
System.out.println(i + " is power of 3");
else
System.out.println(i + " is NOT power of 3");
@booknara
booknara / PowerN.java
Created April 21, 2016 22:49
Checking the number of Power N
/**
* Created by Daehee Han(@daniel_booknara) on 4/21/16.
*/
public class PowerN {
public static void main(String[] args) {
int base = 3;
for (int i = 1; i < 100; i++) {
if (isPowerN(base, i))
System.out.println(i + " is power of " + base);
else
@booknara
booknara / Power4.java
Created April 21, 2016 22:24
Checking the number of power of 4
public class Power4 {
public static void main(String[] args) {
for (int i = 1; i < 30; i++) {
if (isPower4(i))
System.out.println(i + " is power of 4");
else
System.out.println(i + " is NOT power of 4");
}
}
@booknara
booknara / Power2.java
Last active April 21, 2016 22:21
Checking the number is Power of 2
/**
* Created by Daehee Han(@daniel_booknara) on 4/21/16.
*/
public class Power2 {
public static void main(String[] args) {
for (int i = 1; i < 10; i++) {
if (isPower2(i))
System.out.println(i + " is power of 2");
else
System.out.println(i + " is NOT power of 2");
@booknara
booknara / 0_reuse_code.js
Created April 11, 2016 05:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@booknara
booknara / gist:0aa030b1fea90e528c94
Created March 3, 2016 01:26
QR Code Reader Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="100"
tools:context=".DecoderActivity" >
<LinearLayout
android:layout_width="match_parent"
@booknara
booknara / SignedRequestsHelper.java
Created June 24, 2015 23:51
SignedRequestsHelper
/**********************************************************************************************
* Copyright 2009 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file
* except in compliance with the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS"
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@booknara
booknara / ItemLookupSample.java
Created June 24, 2015 23:48
ItemLookupSample
/**********************************************************************************************
* Copyright 2009 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file
* except in compliance with the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS"
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@booknara
booknara / gist:a7d29317d6937c84d531
Last active August 29, 2015 14:11
How to set the part of the text view is clickable like "Terms of Service" or "Privacy Policy"
private void setClickableMessage(TextView textView) {
String message = "By signing up, you agree to our Terms of Service";
String linkText = "Terms of Service";
int indexStart = message.indexOf(linkText);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setText(message, TextView.BufferType.SPANNABLE);
Spannable spannable = (Spannable)textView.getText();
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {