Skip to content

Instantly share code, notes, and snippets.

View mikeseif's full-sized avatar

Michael Seifollahi mikeseif

View GitHub Profile
@mikeseif
mikeseif / SlideTransformer (Zoom out transition)
Last active December 11, 2015 07:38
SlideTransformer I'm using for a presentation, it scales the slides down smoothly by the scaleFactor given in the constructor. @TargetApi set to Honeycomb for lint, I haven't tested on Gingerbread yet and it may need tweaking. Instantiate after setting your adapter for the ViewPager with: mViewPager.setPageTransformer(true, new SlideTransformer(…
/**
* {@link android.support.v4.view.ViewPager.PageTransformer} to scale pages
* as they are slid left / right.
*
* @author michaelseifollahi
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private class SlideTransformer implements PageTransformer {
private final float fScaleFactor;
@mikeseif
mikeseif / SlidingTransformer.java
Last active December 11, 2015 07:38
SlideTransformer for a Photo gallery pager I'm working on, it behaves similar to the paging of the stock App Launcher. Pages zoom / fade in as if they were stacked on top of each other, with the leaving page translating out to the left. @TargetApi set to Honeycomb for lint, I haven't tested on Gingerbread yet and it may need tweaking. Instantiat…
/**
* {@link android.support.v4.view.ViewPager.PageTransformer} to translate / transform pages
* as they are slid left / right.
*
* @author michaelseifollahi
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private class SlideTransformer implements PageTransformer {
private final float fScaleFactor;
@mikeseif
mikeseif / iOSAccessorPattern.m
Last active December 24, 2015 08:29
Accessor pattern for iOS properties, UILabel example.
- (UILabel *)lblTitle
{
// Check if the property isn't instantiated yet
if (_lblTitle == nil) {
_lblTitle = [[UILabel alloc] init];
// Disable auto-constraints if you plan to implement your own
[_lblTitle setTranslatesAutoresizingMaskIntoConstraints:NO];
/* Set any one time configuration properties for the label here
@mikeseif
mikeseif / TransitionRect.m
Last active December 31, 2015 06:39
Transition a CGRect to another CGRect by the (CGFloat) ratio provided.
+ (CGFloat)transitionFloat:(CGFloat)float1 toFloat:(CGFloat)float2 byRatio:(CGFloat)ratio
{
return ( ratio * (float2 - float1) );
}
+ (CGRect)transitionRect:(CGRect)rect1 toRect:(CGRect)rect2 byRatio:(CGFloat)ratio
{
if (CGRectIsNull(rect1) || CGRectIsNull(rect2)) {
return CGRectZero;
}
/*
* Copyright (C) 2014 Chris Banes
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@mikeseif
mikeseif / SquareLayout.java
Created July 11, 2014 01:48
Making an Android view / layout square
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int size = 0;
int width = getMeasuredWidth();
int height = getMeasuredHeight();
if (width > height) {
size = height;
} else {
@mikeseif
mikeseif / LogFileStream.java
Created July 30, 2014 15:51
Logging a FileStream
private void logFileStream(FileInputStream fis) {
BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ( (line = reader.readLine()) != null) {
sb.append(line);
}
Log.d("FILESTREAM", sb.toString());
reader.close();
@mikeseif
mikeseif / DesaturateInterpolator
Last active August 29, 2015 14:06
Desaturate the given Color int by the ratio provided, 1.0f for full saturation, 0.0f for max desaturation. Edit the minimum value of 0.2f (or add as an additional param) to alter how low the desaturation can go.
/**
* Desaturate the given color int value by the provided ratio, down to a minimum of 0.2f.
*
* Note: Do not pass R.color ints, resolve the actual color int via
* getResources().getColor(R.color.your_color_name_here).
*
* f(x) = ( startSaturation / 1.0f * ratio ) + ( minSaturation * (1.0f - ratio) )
*
* @param int The color value to desaturate
* @param float The ratio to desatrate by (0.0f - 1.0f)
@mikeseif
mikeseif / AddDeviceArt
Created September 19, 2016 15:29
Example ffmpeg commands to: inset video into padding, overlay the device art frame (transparent png). In this example, the source screen recordings are from a Nexus 6P at 1440x2560, and the device art is 1564x3258. The x and y values are the coordinates that the actual screen content should originate from in the device art.
ffmpeg -i InputVideo.mp4 -vf "pad=width=1565:height=3258:x=59:y=329:color=white" padded_OutputVideo.mp4
ffmpeg -i padded_OutputVideo.mp4 -i Nexus6P_full.png -filter_complex "overlay=x=0:y=0" OverlayVideo.mp4
@mikeseif
mikeseif / gifenc.sh
Created May 12, 2017 21:01
gifenc.sh accepts 2 parameters, the first being width and the second being framerate (going higher than 30 will melt most computers when playing back.. gifenc.sh is just another bash script with the following:
#!/bin/sh
palette="/tmp/palette.png"
filters="fps=$4,scale=$3:-1:flags=lanczos"
ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2