Skip to content

Instantly share code, notes, and snippets.

@vijaysharm
vijaysharm / gist:c664b83e77856fb6b182
Last active August 29, 2015 14:13
Trello job application question

Find an 8 letter string of characters that contains only letters from acdegilmnoprstuw such that the hash(the_string) is 25180466553932 if hash is defined by the following pseudo-code:

Int64 hash (String s) {
  Int64 h = 7   
  String letters = "acdegilmnoprstuw"     
  for(Int32 i = 0; i < s.length; i++) {
      h = (h * 37 + letters.indexOf(s[i]))     
  }
  return h
} 
@vijaysharm
vijaysharm / PaperLoginViewController.m
Last active August 29, 2015 14:14
Facebook Paper Login
#import "PaperLoginViewController.h"
@interface PaperLoginViewController() <UITextFieldDelegate>
@property (strong, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) UITextField *usernameField;
@property (strong, nonatomic) UITextField *passwordField;
@property (strong, nonatomic) UIView *separator;
@property (strong, nonatomic) NSMutableArray *keyboardShownConstraints;
@property (strong, nonatomic) NSMutableArray *keyboardHiddenConstraints;
@vijaysharm
vijaysharm / Activity.java
Last active August 29, 2015 14:22
A Caldendar Drawable (a la Google Calendar)
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
final MenuItem menuItem = menu.add("Jump to Today");
menuItem.setIcon(new CalendarDrawable(24));
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}
@vijaysharm
vijaysharm / WeekPager.java
Last active January 21, 2016 23:30
A Calendar View pager
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.support.annotation.ColorRes;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
@vijaysharm
vijaysharm / Example.java
Created August 1, 2015 01:00
Sectioned RecyclerView
public class Example {
private static final class SectionViewHolder extends RecyclerView.ViewHolder {
private final TextView title;
public SectionViewHolder(View view) {
super(view);
title = (TextView)view.findViewById(R.id.title);
}
public void bind(String section) {
title.setText(section);
@vijaysharm
vijaysharm / RxAdapter.java
Created September 8, 2015 19:44
On-demand model loading for Android ListView with large number of items
import android.content.Context;
import android.util.LruCache;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import rx.Observable;
import rx.Subscription;
public class Trello {
public static void main(String[] args){
divide_and_conquer(491454843L, "acdegilmnoprstuw", 5);
}
public static void divide_and_conquer(long target, String letters, int size) {
char[] test = new char[size];
for (int index = 0; index < size; index++)
test[index] = 'a';
/*
This example shows how to use getDistributionStatus method in the TestFairy SDK.
getDistributionStatus queries the server about the app version currently running on device, and checks
to see if "Distribution" is set to "Enabled" in Build Settings page.
The example below will close the app if the distribution was disabled. If there is a newer version of
this app uploaded to TestFairy, and it is set to "Distribution" => "Enabled", then the code will open a url to
the new version, offloading to the operating system to install the app.
*/
[TestFairy getDistributionStatus:appToken callback:^(NSDictionary<NSString *,NSString *> *response, NSError *error) {
if (error != nil) {
@vijaysharm
vijaysharm / README.md
Last active April 22, 2021 03:11
XState State Machine for Swift

XState for Swift

This is a rough implementation of the javascript XState library by davidkpiano.

I was looking around for a finite state machine for Swift, and decided to port over the javascript library.

It's not as flexible as the javascript library, but does have that Swift type safety-ness.

TODO