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 / mouse_control.py
Last active Jun 25, 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)
@sheharyarn
sheharyarn / ruby_method_search.rb
Last active Aug 29, 2015
Search an Object's Methods in Ruby easily
View ruby_method_search.rb
# Create a method 'search_methods' for the Object Class
class Object
def search_methods(qry)
self.methods & self.methods.select { |m| m.to_s.include? qry.to_s }
end
end
# Now search methods for any Ruby Object
Array.search_methods 'enum' # => [:to_enum, :enum_for]
Player.last.search_methods :trust # => [:untrust, :untrusted?, :trust]
@sheharyarn
sheharyarn / api_controller.rb
Last active Jan 18, 2021
Render API Errors in Rails
View api_controller.rb
class APIController < ApplicationController
include JSONErrors
# ...
end
@sheharyarn
sheharyarn / mongo_backup.sh
Last active Jul 2, 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 / README.md
Last active Aug 29, 2015
Rails Server Shortcuts
View README.md

Rails Server Shortcuts

Running this script will create three shortcuts (aliases) on your Server:

  • rc - Runs rails console in production
  • cdapp - CDs you into the current release of your app (capistrano)
  • applogs - Starts tailing the production.log of the current release of your app.

This script follows the ~/apps/appname/current directory structure.

@sheharyarn
sheharyarn / SQLiteHelper.java
Created Nov 12, 2014
Java: Create Tables in SQLite beautifully
View SQLiteHelper.java
public class SQLiteHelper extends SQLiteOpenHelper {
private static final String BOOK_TABLE = "books";
private static final HashMap<String, String> BOOK_FIELDS = new HashMap<String, String>() {{
put("title", "TEXT");
put("author", "TEXT");
put("sales", "INTEGER"); // Neatly write fields and their types
}};
// ...
@sheharyarn
sheharyarn / APIClient.java
Last active Aug 29, 2015
Using AndroidAsyncHttp Library
View APIClient.java
RequestParams params = new RequestParams();
params.put("email", "a@b.c");
params.put("password", "12345678");
APIClient.post("/login", params, new JsonHttpResponseHandler() {
// @Override them all
public void onStart() { } // Runs before anything else
public void onFinish() { } // Runs after everything else
@sheharyarn
sheharyarn / inline-asynctask.java
Last active Mar 30, 2020
Android in-line AsyncTask
View inline-asynctask.java
// The Very Basic
new AsyncTask<Void, Void, Void>() {
protected void onPreExecute() {
// Pre Code
}
protected Void doInBackground(Void... unused) {
// Background Code
return null;
}
protected void onPostExecute(Void unused) {
@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 / keybase.md
Created Jan 7, 2015
My Verification on Keybase.io
View keybase.md

Keybase proof

I hereby claim:

  • I am sheharyarn on github.
  • I am sheharyar (https://keybase.io/sheharyar) on keybase.
  • I have a public key whose fingerprint is 7D2B 59DB 7F60 9FD7 F4C4 E781 FA1F 9B9B 68FE B6FF

To claim this, I am signing this object: