Skip to content

Instantly share code, notes, and snippets.

View sheharyarn's full-sized avatar
🕶️
Working

Sheharyar Naseer sheharyarn

🕶️
Working
View GitHub Profile
@sheharyarn
sheharyarn / app-context.js
Last active August 12, 2021 14:43
Custom Wrapper around React Contexts
/**
* Custom Implementation of React Context to manage
* global application state
*
* @author Sheharyar Naseer (@sheharyarn)
* @license MIT
*
* Normal Usage:
*
* ```
@sheharyarn
sheharyarn / CardSwingAnimations.md
Last active March 16, 2021 08:04
Swing Animations for CardViews in Android

SwingUp Animations for Android

I use these snippets to implement Google Now Card appear-animations on Android. Add these two files to your res/anim/ folder and add a swing_anim_time integer to your values:

<!-- res/values/strings.xml -->
<integer name="swing_anim_time">750</integer>
@sheharyarn
sheharyarn / SimpleRVAdapter.java
Last active February 9, 2021 10:11
Simple Recycler View adapter (without XML layout)
/**
* SimpleRVAdapter to quickly get started with simple Lists in Recyclerview
*
* Usage:
*
* RecyclerView rv = (RecyclerView)findViewById(R.id.rv);
* rv.setLayoutManager(new LinearLayoutManager(getContext()));
* rv.setAdapter(new SimpleRVAdapter(new String[] {"1", "2", "3", "4", "5", "6", "7"}));
*
* @author Sheharyar Naseer
@sheharyarn
sheharyarn / RVEmptyObserver.java
Created May 13, 2017 13:55
Set Empty Layout for RecyclerViews in Android
/**
* Custom implementation of AdapterDataObserver to show empty layouts
* for RecyclerView when there's no data
*
* Usage:
*
* adapter.registerAdapterDataObserver(new RVEmptyObserver(recyclerView, emptyView));
*/
public class RVEmptyObserver extends RecyclerView.AdapterDataObserver {
private View emptyView;
@sheharyarn
sheharyarn / create_image_attachment.rb
Last active January 18, 2021 15:13
Polymorphic Paperclip class with unique partial ActiveRecord index on :default_image
# db/migrations/xxxxxxxxxxxxxx_create_image_attachment.rb
class CreateImageAttachments < ActiveRecord::Migration[5.0]
def change
create_table :image_attachments do |t|
t.belongs_to :imageable, polymorphic: true
t.attachment :data
t.boolean :default, default: false
t.timestamps
end
@sheharyarn
sheharyarn / api_controller.rb
Last active January 18, 2021 15:13
API Authentication with Devise in Rails
class API::BaseController < ApplicationController
def index
render json: { active: true }
end
def authenticate
if user = User.authenticate(request.headers['X-AUTH-TOKEN'])
sign_in(user, store: false)
@sheharyarn
sheharyarn / memoize.ex
Last active September 27, 2020 10:05
Simple Memoization in Elixir (using FastGlobal)
defmodule Memoize do
@moduledoc """
Simple memoization helper built on top of FastGlobal.
Remember to add `{:fastglobal, "~> 1.0"}` to your
dependencies first.
## Usage
@sheharyarn
sheharyarn / gmail-recruiter-reply.appscript.js.gs
Last active July 23, 2020 12:04
Google Appscript to auto-reply to recruiters
function respondToEmails() {
//var filter = 'from:(some.email@address.com) AND -label:"Auto-Replied"';
var filter = 'label:"Job Proposals" AND -label:"Auto-Replied"';
var completeLabel = GmailApp.getUserLabelByName("Auto-Replied");
var threads = GmailApp.search(filter);
var replyFrom = "Recruiter Bot <your.email+recruiterbot@gmail.com>";
val realEmail = "your.real@email.com"
var formLink = "https://link.to/your/form"
var response = (
@sheharyarn
sheharyarn / twitter_deleter.ex
Last active April 15, 2020 18:23
Delete all of your tweets before a certain date
defmodule TwitterDeleter do
@tweet_data Path.expand("~/Downloads/twitterdump/assets/tweet.js")
@cutoff Date.from_iso8601!("2015-01-01")
@call_limit 3000
@chunk_no 3
require Logger
def run do
file = File.read!(@tweet_data)
@sheharyarn
sheharyarn / simple-elixir-app.dockerfile
Last active April 15, 2020 16:01
Minimal Dockerfile for simple Elixir applications
# Build the release
# -----------------
FROM elixir:1.9.0-alpine as build
ENV MIX_ENV=prod
WORKDIR /source
RUN mix local.hex --force && mix local.rebar --force
# Cache dependencies