Skip to content

Instantly share code, notes, and snippets.

@naoyeye
naoyeye / angular.filters.nl2br.js
Created January 2, 2014 14:36
angular nl2br filter
/*
# Usage in html template:
"xxx | nl2br"
<div ng-bind-html=" YourString | nl2br "></div>
or:
@Mao8a
Mao8a / fix-to-iOS-iframe-height-issue.html
Created July 10, 2013 05:21
HTML: Fix to iOS iframe height issue
Fix to iOS iframe height issue
<iframe id="stupid-iframe" height="200" src="a-file.html"></iframe>
<html>
<body>
<div class="iframe-wrapper" style="width: 100%; height: 200px; overflow: auto; -webkit-overflow-scrolling: touch;">
</div>
</body>
@ls-lukebowerman
ls-lukebowerman / sitemap.xml.erb
Created August 7, 2012 17:59
Sitemap (sitemaps.org) generator for Middleman
<% pages = sitemap.resources.find_all{|p| p.source_file.match(/\.html/) } %>
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<% pages.each do |p| %>
<url>
<loc>http://youdomain.com/<%=p.destination_path.gsub('/index.html','')%></loc>
<priority>0.7</priority>
</url>
<% end %>
</urlset>
@rewonc
rewonc / app.js
Last active October 26, 2021 00:16
AngularJS/PhoneGap/Ionic: filter to convert links for opening in separate mobile window
//*
//* See the JS Fiddle: http://jsfiddle.net/sxcjmoj5/3/
//*
//*
// make sure ngSanitize module is installed:
// https://docs.angularjs.org/api/ngSanitize
//
// To convert links from plaintext, you must use the linky filter which is included with ngSanitize
// https://docs.angularjs.org/api/ngSanitize/filter/linky
//
@dmilisic
dmilisic / active_record_enum_with_rails_admin.rb
Last active January 21, 2022 10:50
Initializer for handling ActiveRecord (4.1+) enums by RailsAdmin (0.6.2)
module ActiveRecord
module RailsAdminEnum
def enum(definitions)
super
definitions.each do |name, values|
define_method("#{ name }_enum") { self.class.send(name.to_s.pluralize).to_a }
define_method("#{ name }=") do |value|
if value.kind_of?(String) and value.to_i.to_s == value
@amfeng
amfeng / callback.erb
Last active August 8, 2022 19:33
Stripe OAuth Example -- Ruby
<!doctype html>
<head>
<title>Stripe OAuth Example</title>
</head>
<body>
<%= @access_token %>
</body>
</html>
@jcasimir
jcasimir / friendly_urls.markdown
Created September 11, 2011 15:48
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@dsheiko
dsheiko / strtr.js
Last active July 9, 2023 18:18
Java-script strtr — translate characters or replace substrings
/**
* strtr() for JavaScript
* Translate characters or replace substrings
*
* @author Dmitry Sheiko
* @version strtr.js, v 1.0.2
* @license MIT
* @copyright (c) Dmitry Sheiko http://dsheiko.com
**/
@thebucknerlife
thebucknerlife / authentication_with_bcrypt_in_rails_4.md
Last active January 17, 2024 23:54
Simple Authentication in Rail 4 Using Bcrypt

#Simple Authentication with Bcrypt

This tutorial is for adding authentication to a vanilla Ruby on Rails app using Bcrypt and has_secure_password.

The steps below are based on Ryan Bates's approach from Railscast #250 Authentication from Scratch (revised).

You can see the final source code here: repo. I began with a stock rails app using rails new gif_vault

##Steps

@stream7
stream7 / migration_integer_limit_option
Created July 7, 2011 14:09
Rails migrations integer :limit option
literally always have to look up the meaning of :limit in migrations when it comes to integer values. Here's an overview. Now let's memorise it (oh, this works for MySQL, other databases may work differently):
:limit Numeric Type Column Size Max value
1 tinyint 1 byte 127
2 smallint 2 bytes 32767
3 mediumint 3 byte 8388607
nil, 4, 11 int(11) 4 byte 2147483647
5..8 bigint 8 byte 9223372036854775807
Note: by default MySQL uses signed integers and Rails has no way (that I know of) to change this behaviour. Subsequently, the max. values noted are for signed integers.