Skip to content

Instantly share code, notes, and snippets.

View yfujiki's full-sized avatar
💭
Moving around

Yuichi Fujiki yfujiki

💭
Moving around
  • Athlee Ltd
  • Japan
View GitHub Profile
@yfujiki
yfujiki / UIScrollViewDelegate-layoutImages.swift
Last active February 5, 2019 05:48
Infinite Scrolling with UIScrollView
private func layoutImages() {
let w = scrollView.frame.size.width
let h = scrollView.frame.size.height
imageViews.enumerated().forEach { (index: Int, imageView: UIImageView) in
imageView.image = images[index]
imageView.frame = CGRect(x: w * CGFloat(index),
y: 0,
width: w,
height: h)
}
class MainActivityFragment : Fragment() {
// Discard permanent reference to the adapter
val adapter = MainRecyclerViewAdapter()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
return inflater.inflate(R.layout.fragment_activity_main, container, false)
}
+ override fun onDestroyView() {
class MainActivityFragment : Fragment() {
// Discard permanent reference to the adapter
- val adapter = MainRecyclerViewAdapter()
-
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
return inflater.inflate(R.layout.fragment_activity_main, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@yfujiki
yfujiki / MainActivityFragment.kt
Last active February 5, 2019 05:38
RecyclerViewMemoryLeak
class MainActivityFragment : Fragment() {
// Fragment keeps the reference to the RecyclerView adapter
private lateinit var adapter: MainRecyclerViewAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
adapter = MainRecyclerViewAdapter()
retainInstance = true
}
@yfujiki
yfujiki / BackgroundMatchers.kt
Last active January 21, 2019 16:03
Custom matcher for Espresso to check whether the background shape has a border or not
//
// Usage :
// onView(withId(R.id...)
// .check(
// ViewAssertions.matches(
// BackgroundViewMatchers.backgroundHasBorder()
// )
// )
// )
//
@yfujiki
yfujiki / Record gif from connected Android device screen
Created January 17, 2019 20:00
Record gif from connected Android device screen. Slightly modified the script from https://gist.github.com/sveinungkb/3a5753da908489fc0c26
#!/bin/sh
PREFIX="Screenshot-$(date +%Y%m%d-%H%M%S)"
BASE="/sdcard/$PREFIX"
OUTPUT="$YOUR_OUT_PUT_DIRECTORY" # Need to modify this to suit your environment
DELAY=30
trap ctrl_c INT
function clean_up() {
@yfujiki
yfujiki / iOS simulator screen recording to gif
Last active January 17, 2019 19:04
Slightly modified Alfred Script of https://github.com/alexp2ad/record-ios-simulator to create gif version from mp4.
#!/bin/bash
# Starts and stops recording in the simulator
# Set your prefered output directory here
outputDirectory=~/Desktop/
# Open recordings in the default app when ending recording
openRecordings=true
@yfujiki
yfujiki / snap helper.kt
Created December 15, 2018 08:21
SnapHelper that achieves ViewPager like snap for RecyclerView
val snapHelper = object : LinearSnapHelper() {
override fun findTargetSnapPosition(
layoutManager: RecyclerView.LayoutManager?,
velocityX: Int,
velocityY: Int
): Int {
val centerView = findSnapView(layoutManager!!) ?: return RecyclerView.NO_POSITION
var targetPosition = layoutManager.getPosition(centerView)
if (currentPosition != targetPosition) {
@yfujiki
yfujiki / gist:77df1725be99a3750634
Last active August 1, 2017 08:56
Simple dispatch_group and dispatch_semaphore sample
//: Playground - noun: a place where people can play
import Foundation
// DispatchGroup sample.
// we are waiting for all async blocks to be finished before typing "[Dispatch Group] sample has finished"
let group = DispatchGroup()
let q1 = DispatchQueue.global(qos: .background)
let q2 = DispatchQueue.global(qos: .background)
@yfujiki
yfujiki / tile.sh
Created May 1, 2014 19:56
Create tile images of 256x256, zooming 100%, 50% and 25%
#!/bin/bash
file=$1
function tile() {
convert $file -scale ${s}%x -crop 256x256 \
-set filename:tile "%[fx:page.x/256]_%[fx:page.y/256]" \
+repage +adjoin "${file%.*}_${s}_%[filename:tile].${file#*.}"
}
s=100
tile
s=50