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 / 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 / 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 / flatten.rb
Last active April 20, 2017 01:32
Ruby implementation of Array#flatten
class Array
## Returns a new flattened array
def custom_flatten
new_array = []
# Recursively iterate over sub-arrays and other
# elements and concat them to the new array
self.each do |obj|
if obj.is_a?(Array)
@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 / 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 / reddup_video_controls.js
Created March 11, 2018 05:19
Reddup video controls script for GreaseMonkey / Tampermonkey
// ==UserScript==
// @name Reddup Video Controls
// @version 0.1.0
// @namespace https://www.reddup.co/
// @homepageURL https://sheharyar.me/
// @author Sheharyar Naseer
// @description Show Video Controls for all videos on Reddup
// @include http*://www.reddup.co/*
// @license MIT
// ==/UserScript==
@sheharyarn
sheharyarn / flatten.exs
Created September 3, 2018 22:08
Flatten a List in Elixir (Custom Implementation)
defmodule Flatten do
@doc """
Flattens a List in Elixir
## Examples
```
Flatten.flatten([1,2,3,4])
# => [1,2,3,4]
@sheharyarn
sheharyarn / SimpleJSON.java
Last active March 13, 2019 17:44
Simple Java Class to convert Lists/Maps to JSON and vice versa
public class SimpleJSON {
/**
* @author: Sheharyar Naseer (@sheharyarn)
* @license: MIT
*/
public static Object toJSON(Object object) throws JSONException {
if (object instanceof HashMap) {
JSONObject json = new JSONObject();
HashMap map = (HashMap) object;
@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
*/
@sheharyarn
sheharyarn / capistrano.nginx.rake
Created June 27, 2015 20:53
Nginx Tasks for Capistrano 3
# Add this file to "rails_app/lib/capistrano/tasks/nginx.rake"
# This will create these tasks:
# - cap stage nginx:start
# - cap stage nginx:stop
# - cap stage nginx:restart
# - cap stage nginx:reload
# Because of "sudo", you'll have to put nginx commands in your visudo file
# See this: https://gist.github.com/sheharyarn/f3d98e8cc859f092532b