Skip to content

Instantly share code, notes, and snippets.

View TechFounder's full-sized avatar

Jimmy Chen TechFounder

View GitHub Profile
@TechFounder
TechFounder / view.haml
Created September 23, 2014 21:55
Prevent link_to from redirecting to a new page when you don't have any particular link to go to. So you don't get that annoying top of the page action.
= link_to 'Link to Nowhere', 'javascript:;'
@TechFounder
TechFounder / hide_unhide.coffee
Last active August 29, 2015 14:06
CoffeeScript to use with checkbox to hide / unhide form fields or div.
# Use this if you only want to use the checkbox as a clicker
$('#checkbox-id').click ->
$('.what-you-want-to-hide').slideToggle('slow')
# Use this if you actually care about checking to see if the checkbox has been checked
$('#checkbox-id').click ->
if $(@).prop('checked')
$('.what-you-want-to-hide, .what-you-want-to-hide-also').slideDown 'slow'
else
$('.what-you-want-to-hide, .what-you-want-to-hide-also').slideUp 'slow'
@TechFounder
TechFounder / configfolder.yml
Created June 1, 2014 16:56
secret - Figaro Gem vs Rails 4.1 These two files shows the difference in configuration between the two methods of keeping environment variables secret.
# figaro gem
# config/application.yml
stripe_publishable_key: pk_test_TLr0qqdKhm0yX1bZtKC4kFAC
stripe_secret_key: sk_test_Qbppb2nkFEzPoquOdBym0JL2
# rails 4.1
# config/secrets.yml
stripe_publishable_key: pk_test_TLr0qqdKhm0yX1bZtKC4kFAC
stripe_secret_key: sk_test_Qbppb2nkFEzPoquOdBym0JL2
@TechFounder
TechFounder / index.html
Last active August 29, 2015 13:57
You want a way to center any object to the middle of the page (horizontal centering)?
<div id="first">
<div id="second">
Item you want centered
</div>
</div>
for example:
<a href="mailto:info@email.com?Subject=Web%20Page" target="_top" id="first">
<img src="photo.png" alt="photo">
@TechFounder
TechFounder / assets.css.scss
Last active August 29, 2015 13:56
A useful jQuery snippet to make any tagged item a clickable link. This is how in Rails.
[data-link] {
cursor: pointer;
}
@TechFounder
TechFounder / simple_form_bootstrap3.rb
Last active January 2, 2016 13:09
Use this configuration in your initializer for simple_form if you're using bootstrap 3. https://github.com/gregbell/active_admin/issues/2703
SimpleForm.setup do |config|
config.input_class = 'form-control'
config.boolean_style = :nested
config.wrappers :bootstrap3, tag: 'div', class: 'form-group', error_class: 'has-error',
defaults: { input_html: { class: 'default_class' } } do |b|
b.use :html5
@TechFounder
TechFounder / form.htm.erb
Created January 1, 2014 16:01
How to add value to input area in rails form.
<div class="form-inputs">
<%= f.input :title, :input_html => { :value => "This is title field value." } %>
<%= f.input :body, :input_html => { :value => "This is body field value." } %>
</div>
or
<div class="form-inputs">
<%= f.input :title, input_html: { :value => "This is title field value." } %>
<%= f.input :body, input_html: { :value => "This is body field value." } %>
@TechFounder
TechFounder / freq.tsv
Created December 20, 2013 17:05
Reusable bar chart snippet from the site Tributary. http://tributary.io/inlet/8057896
letter frequency
A .08167
B .01492
C .02780
D .04253
E .12702
F .02288
G .02022
H .06094
I .06973
@TechFounder
TechFounder / sessions_helper.rb
Created December 14, 2013 16:50
Cookies syntax built into Rails
module SessionsHelper
def sign_in(user)
cookies.permanent[:remember_token] = user.remember_token
self.current_user = user
end
end
# You can use cookies as if it were a hash even though it's not as it's actually saves a piece of text on the bowser.
# Each element in the cookies is itself a hash of two elements, a value and an optional expires date.
@TechFounder
TechFounder / routes.rb
Created November 19, 2013 20:49
To change the URL for Devise sign in and sign out to login and logout.
devise_for :users, path_names: {sign_in: "login", sign_out: "logout"}