This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* RVFragment - Fragment with a simple RecyclerView that | |
* only takes Strings | |
* | |
* Usage: | |
* RVFragment rvf = new RVFragment(); | |
* | |
* @author Sheharyar Naseer | |
*/ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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--) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Axios Request Wrapper | |
* --------------------- | |
* | |
* @author Sheharyar Naseer (@sheharyarn) | |
* @license MIT | |
* | |
*/ | |
import axios from 'axios' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |