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 / mouse_control.py
Last active June 27, 2022 20:23
Control your Mouse using your Eye Movement
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 August 29, 2015 13:59
Search an Object's Methods in Ruby easily
# 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 April 27, 2022 08:53
Render API Errors in Rails
class APIController < ApplicationController
include JSONErrors
# ...
end
@sheharyarn
sheharyarn / mongo_backup.sh
Last active January 23, 2024 16:54
Mongodump Shell Script for Cronjob
#!/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 August 29, 2015 14:05
Rails Server Shortcuts

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 November 12, 2014 22:25
Java: Create Tables in SQLite beautifully
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 August 29, 2015 14:10
Using AndroidAsyncHttp Library
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 March 30, 2020 10:01
Android in-line AsyncTask
// 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 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 / keybase.md
Created January 7, 2015 22:52
My Verification on Keybase.io

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: