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 / bitcoin.conf
Last active March 2, 2018 08:47
Quickly work with BTC Testnet
testnet=1
server=1
# enable SSL for RPC server
#rpcssl=1
rpcallowip=0.0.0.0/0
rpcuser=admin
rpcpassword=123
@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 / 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 / serialize_query.js
Created March 5, 2017 05:20
Serialize an Object into URI Query in Javascript
/**
* This method converts a Javascript object into
* a URI query string. Also handles nested arrays
* and objects (in Rails / PHP syntax)
*
* @author Sheharyar Naseer (@sheharyarn)
* @license MIT
*
* @example
*
@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 / request.js
Last active August 24, 2023 14:55
Axios Request Wrapper for React (https://to.shyr.io/axios-requests)
/**
* Axios Request Wrapper
* ---------------------
*
* @author Sheharyar Naseer (@sheharyarn)
* @license MIT
*
*/
import axios from 'axios'
@sheharyarn
sheharyarn / deploy.sh
Last active February 20, 2018 14:38
Static Website Bash Deployment Script
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
#set -o xtrace
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
__base="$(basename ${__file} .sh)"
@sheharyarn
sheharyarn / bash-boilerplate.sh
Created October 29, 2016 21:51
Bash Script Boilerplate code
#!/usr/bin/env bash
# Bash3 Boilerplate. Copyright (c) 2014, kvz.io
set -o errexit
set -o pipefail
set -o nounset
# set -o xtrace
# Set magic variables for current file & dir
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@sheharyarn
sheharyarn / validate_credit_card.js
Created September 20, 2016 20:57 — forked from DiegoSalazar/validate_credit_card.js
Luhn algorithm in Javascript. Check valid credit card numbers
// takes the form field value and returns true on valid number
function valid_credit_card(value) {
// accept only digits, dashes or spaces
if (/[^0-9-\s]+/.test(value)) return false;
// The Luhn Algorithm. It's so pretty.
var nCheck = 0, nDigit = 0, bEven = false;
value = value.replace(/\D/g, "");
for (var n = value.length - 1; n >= 0; n--) {
@sheharyarn
sheharyarn / RVFragment.java
Last active December 18, 2019 06:39
A simple Fragment with RecyclerView
/**
* RVFragment - Fragment with a simple RecyclerView that
* only takes Strings
*
* Usage:
* RVFragment rvf = new RVFragment();
*
* @author Sheharyar Naseer
*/