Skip to content

Instantly share code, notes, and snippets.

View AnkurVyas-BTC's full-sized avatar
🎯
Karma rules world... You get whatever you give!

Ankur Vyas AnkurVyas-BTC

🎯
Karma rules world... You get whatever you give!
View GitHub Profile
@AnkurVyas-BTC
AnkurVyas-BTC / mocha_test_blog_calculator.js
Created June 26, 2017 18:15
Simple calculator js file for tests
function add(arg1, arg2) {
return arg1 + arg2;
}
function subtract(arg1, arg2) {
return arg1 - arg2;
}
function multiply(arg1, arg2) {
return arg1 * arg2;
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@AnkurVyas-BTC
AnkurVyas-BTC / mail_chimp_email_change.json
Last active June 3, 2017 10:42
Mailchimp change email JSON
{
"type": "upemail",
"fired_at": "<time>",
"data": {
"new_id": "a0dcb064ff",
"new_email": "<TEST_NEW_EMAIL>",
"old_email": "<TEST_OLD_EMAIL>",
"list_id": "123456"
}
}
@AnkurVyas-BTC
AnkurVyas-BTC / handlebars_partial.js
Created May 23, 2017 18:59
Partial for handlebars
Handlebars.registerPartial('getButton',
"<button class='{{className}}' data-book-id={{id}}>{{text}}</button>"
);
@AnkurVyas-BTC
AnkurVyas-BTC / handlebars_format_name_helper.js
Created May 23, 2017 18:21
Format name helper for handlebars
Handlebars.registerHelper('formatName', function (name) {
return 'Mr. ' + name;
});
data = [
{
"id": 1,
"name": "Javascript",
"price": 80,
"author": "Author-1"
},
{
"id": 2,
"name": "Ruby",
@AnkurVyas-BTC
AnkurVyas-BTC / handlebars_helpers.hbs
Last active May 23, 2017 18:44
Handlebars helpers builtin as well as custom
{{#books}}
{{#if price}}
<tr>
<td>{{name}}</td>
<td>{{price}}</td>
<td>{{formatName author}}</td>
<td>
{{> getButton className="edit-book btn btn-warning" text="Edit"}}
{{> getButton className="delete-book btn btn-danger" text="Delete"}}
</td>
@AnkurVyas-BTC
AnkurVyas-BTC / handlebar-rails_get_books.js
Last active March 12, 2017 18:48
Ajax call to get books
$.get('/books', function (data) {
booksListHtml = HandlebarsTemplates['book_list']({
books: data
});
$('#book-list').html(booksListHtml);
});
@AnkurVyas-BTC
AnkurVyas-BTC / handlebar-rails_book_list.hbs
Created March 12, 2017 13:58
Listing books handle bar template.
<div class="row">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Book Name</th>
<th>Book Price</th>
<th>Author</th>
<th>Actions</th>
</tr>
</thead>
@AnkurVyas-BTC
AnkurVyas-BTC / RubyUtils.js
Created March 9, 2017 13:53 — forked from borgateo/RubyUtils.js
Ruby's String Utils: center, rjust, ljust in JS
/*
* Ruby's String#center, String#rjust, String#ljust
*
* https://jsfiddle.net/6v0bpffm/
*/
function ljust( string, width, padding ) {
padding = padding || " ";
padding = padding.substr( 0, 1 );
if ( string.length < width )