Answer: The primary constructor is part of the class header. Unlike Java, you don't need to declare a constructor in the body of the class. Here's an example:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context | |
import android.hardware.Sensor | |
import android.hardware.SensorEvent | |
import android.hardware.SensorEventListener | |
import android.hardware.SensorManager | |
import androidx.compose.animation.ExperimentalAnimationApi | |
import androidx.compose.animation.core.animateFloatAsState | |
import androidx.compose.foundation.Image | |
import androidx.compose.foundation.background | |
import androidx.compose.foundation.layout.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loader = Instaloader() | |
NUM_POSTS = 10 | |
def get_hashtags_posts(query): | |
posts = loader.get_hashtag_posts(query) | |
users = {} | |
count = 0 | |
for post in posts: | |
profile = post.owner_profile | |
if profile.username not in users: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from instaloader import Instaloader, Profile | |
import datetime | |
MAX_DAYS = 50 | |
LIKES_WEIGHT = 1 | |
COMMENTS_WEIGHT = 1 | |
NUM_FOLLOWERS_WEIGHT = 1 | |
NUM_POSTS_WEIGHT = 1 |
FWIW: I (@rondy) am not the creator of the content shared here, which is an excerpt from Edmond Lau's book. I simply copied and pasted it from another location and saved it as a personal note, before it gained popularity on news.ycombinator.com. Unfortunately, I cannot recall the exact origin of the original source, nor was I able to find the author's name, so I am can't provide the appropriate credits.
- By Edmond Lau
- Highly Recommended 👍
- http://www.theeffectiveengineer.com/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Result: 1 | |
Items { | |
TemplateId: "BADGE_BATTLE_ATTACK_WON" | |
Badge { | |
BadgeType: BADGE_BATTLE_ATTACK_WON | |
BadgeRanks: 4 | |
Targets: "\nd\350\007" | |
} | |
} | |
Items { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// it returns a square thumbnail. | |
func getAssetThumbnail(asset: PHAsset, size: CGFloat) -> UIImage { | |
let retinaScale = UIScreen.mainScreen().scale | |
let retinaSquare = CGSizeMake(size * retinaScale, size * retinaScale) | |
let cropSizeLength = min(asset.pixelWidth, asset.pixelHeight) | |
let square = CGRectMake(0, 0, CGFloat(cropSizeLength), CGFloat(cropSizeLength)) | |
let cropRect = CGRectApplyAffineTransform(square, CGAffineTransformMakeScale(1.0/CGFloat(asset.pixelWidth), 1.0/CGFloat(asset.pixelHeight))) | |
let manager = PHImageManager.defaultManager() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onNext(ArrayList<Phrase> phrases) { | |
ArrayList<Integer> phraseIDs = new ArrayList<>(); | |
Observable | |
.from(phrases) | |
.collect(phraseIDs, new Action2<ArrayList<Integer>, Phrase>() { | |
@Override | |
public void call(ArrayList<Integer> integers, Phrase phrase) { | |
integers.add(phrase.getId()); | |
} |