Skip to content

Instantly share code, notes, and snippets.

Avatar
🕶️
Working on @slab, @sturama & @gdg-x

Sheharyar Naseer sheharyarn

🕶️
Working on @slab, @sturama & @gdg-x
View GitHub Profile
@sheharyarn
sheharyarn / nginx.overrides
Created Jun 27, 2015
Restart / Reload Nginx without Entering Sudo Password
View nginx.overrides
# Enter this command to create a sudoers override/include file:
# sudo visudo -f /etc/sudoers.d/nginx.overrides
# (Make sure you actually have this in your /etc/sudoers - Run `sudo visudo` to check)
# #includedir /etc/sudoers.d
# This file assumes your deployment user is `deploy`
# Nginx Commands
Cmnd_Alias NGINX_RESTART = /usr/sbin/service nginx restart
@sheharyarn
sheharyarn / mouse_control.py
Last active May 29, 2021
Control your Mouse using your Eye Movement
View mouse_control.py
import zmq
from pymouse import PyMouse
#mouse setup
m = PyMouse()
x_dim, y_dim = m.screen_size()
#network setup
context = zmq.Context()
socket = context.socket(zmq.SUB)
View request.js
/**
* Axios Request Wrapper
* ---------------------
*
* @author Sheharyar Naseer (@sheharyarn)
* @license MIT
*
*/
import axios from 'axios'
@sheharyarn
sheharyarn / mongo_backup.sh
Last active May 26, 2021
Mongodump Shell Script for Cronjob
View mongo_backup.sh
#!/bin/bash
MONGO_DATABASE="your_db_name"
APP_NAME="your_app_name"
MONGO_HOST="127.0.0.1"
MONGO_PORT="27017"
TIMESTAMP=`date +%F-%H%M`
MONGODUMP_PATH="/usr/bin/mongodump"
BACKUPS_DIR="/home/username/backups/$APP_NAME"
@sheharyarn
sheharyarn / app-context.js
Last active May 12, 2021
Custom Wrapper around React Contexts
View app-context.js
/**
* Custom Implementation of React Context to manage
* global application state
*
* @author Sheharyar Naseer (@sheharyarn)
* @license MIT
*
* Normal Usage:
*
* ```
@sheharyarn
sheharyarn / CardSwingAnimations.md
Last active Mar 16, 2021
Swing Animations for CardViews in Android
View CardSwingAnimations.md

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 Feb 9, 2021
Simple Recycler View adapter (without XML layout)
View SimpleRVAdapter.java
/**
* 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
Set Empty Layout for RecyclerViews in Android
View RVEmptyObserver.java
/**
* 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 Jan 18, 2021
Polymorphic Paperclip class with unique partial ActiveRecord index on :default_image
View create_image_attachment.rb
# 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 Jan 18, 2021
API Authentication with Devise in Rails
View api_controller.rb
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)