Skip to content

Instantly share code, notes, and snippets.

@ygamretuta
ygamretuta / inline_radios_simple_form_boostrap.rb
Last active December 14, 2015 07:58
render inline radio buttons with choices from a collection; this uses simple_form and bootstrap
f.input :choice_field, :as=>:radio_buttons, :item_wrapper_class=>'inline', :collection=>1..4
@ygamretuta
ygamretuta / 0_reuse_code.js
Last active August 29, 2015 14:07
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
<!-- Rails automatically strips tags when outputting strings with html on them -->
<%= '<div>You are not alone</div>' %>
<!-- However, you may want to escape the HTML so that you can display the tags in the output -->
<%= h '<div>This will display with escaped html tags</div>' %>
<!-- There are some instances where you would want text with tags to be actually rendered -->
<%= raw '<div>I will be a div</div><br /><span>I will be under div</div>' %>
@ygamretuta
ygamretuta / bundle.sh
Last active December 14, 2015 01:12
Nokogiri Rails 5 OSX El Capitan Homebrew
bundle config build.nokogiri --with-xml2-dir=/usr/local/Cellar/libxml2/2.9.2
bundle install
// app.module.ts
import { ModalModule } from 'ng2-bootstrap';
@NgModule({
bootstrap: [AppComponent],
// other code removed for brevity
imports: [
// error if not using forRoot()
ModalModule.forRoot()
]
import { Component, OnInit, ViewChild } from '@angular/core';
import { LazyLoadEvent, DataTable } from 'primeng/primeng';
import { Router, ActivatedRoute } from '@angular/router';
// component
declare var jQuery: any;
params = {page: 1, page_size: 10};
paginator = {total_records: 0, per_page: 10, total_pages: 0, current_page: 1};
@ygamretuta
ygamretuta / truncate-angular2.js
Last active March 7, 2017 10:33
custom pipe that truncates a long string to a certain number of chars; uses lodash
// pipes/truncate.pipe.ts
import { Pipe, PipeTransform } from '@angular/core';
import * as _ from 'lodash';
@Pipe({ name: 'truncate' })
export class TruncatePipe implements PipeTransform {
transform(value: string, chars?: number): string {
let length = chars ? chars : 100;
return _.truncate(value, {length: length });
}
"scripts": {
"ng": "ng",
"heroku-prebuild": "npm install -g http-server",
"heroku-postbuild": "ng build --prod",
"start": "http-server dist/",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
@ygamretuta
ygamretuta / e2e_1.js
Last active March 23, 2017 01:01
$ and $$ on Protractor
// my.e2e-spec.ts
import { $, $$ } from 'protractor';
describe('MyDOM', ()=> {
it('should have a header with my text', () => {
expect($('h1.myHeader').getText()).toBe('My Header');
});
it('should have 3 list items', () => {
expect($$('#myList li').count()).toEqual(3));
@ygamretuta
ygamretuta / e2e_tut.html
Last active March 23, 2017 00:58
e2e tutorial dom
<h1 id="myHeader">My Header</h1>
<ul id="myList">
<li>My Item #1</li>
<li>My Item #1</li>
<li>My Item #1</li>
</ul>