Skip to content

Instantly share code, notes, and snippets.

@ascot21
ascot21 / gist:4068607
Created November 13, 2012 21:45
Step definition for mass-assigning "admin"
Given /^there are the following users:$/ do |table|
table.hashes.each do |attributes|
unconfirmed = attributes.delete("unconfirmed") == "true"
admin = attributes.delete("admin") == "true"
@user = User.create!(attributes)
@user.admin = admin
@user.confirm! unless unconfirmed
end
end
@ascot21
ascot21 / gist:4171325
Created November 29, 2012 19:37
jQuery Easing One-Page
$('nav ul li a').bind('click',function(event){
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: ($($anchor.attr('href')).offset().top)-80
}, 1500,'easeInOutExpo');
event.preventDefault();
@ascot21
ascot21 / gist:5364199
Created April 11, 2013 15:13
working on Rails find_by_or_create
@badge = Badge.find_or_create_by_name_and_user_id(:name => @badge_name,:user_id => current_user.id, :date_approved => "2013-04-10", :completed_credits => 1, :status => 1, :badge_type_id => 12, :user_id => current_user.id).where("status = 1")
@ascot21
ascot21 / gist:5912215
Created July 2, 2013 19:16
Truncating text with CSS
.message {
@include span-columns(12);
font-size: 85%;
overflow : hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
@ascot21
ascot21 / instagram.rb
Created July 4, 2013 17:27
Download images from Instagram
require "restclient"
require "json"
media_url = "https://api.instagram.com/v1/tags/scottisla/media/recent?access_token=ACCESS_TOKEN"
urls = []
while media_url != nil
response = RestClient.get(media_url)
json = JSON.parse(response)
ActiveRecord::RecordNotUnique (PG::Error: ERROR: duplicate key value violates unique constraint "index_students_on_email"
2013-07-05T19:08:13.932777+00:00 app[web.1]: DETAIL: Key (email)=() already exists.
@ascot21
ascot21 / model.js.coffee
Created July 5, 2013 21:33
Override Backbone.sync method on individual model
sync: (method,model,options) ->
if method is "create"
options.beforeSend = (xhr) ->
xhr.setRequestHeader 'X-HTTP-Method-Override', 'PUT'
Backbone.sync(method,model,options)
@ascot21
ascot21 / index.html
Created July 9, 2013 20:49
Loading spinner with CSS
<div id="loading"><div id="spinner"></div> <span>Loading...</span></div>
@ascot21
ascot21 / gist:6040106
Last active December 20, 2015 00:09
the request
{
"nickname": "LB",
"about_me": "I'm a cool sophomore that's in to Poggs.",
"answers": [{
"question_id": 16,
"text": "Theatre, Band, volunteer at Rocketown"
}, {
"question_id": 17,
"text": "I love music and Bob Dylan more than anyone else."
}, {
{
"birth_name": "Lynn Braun",
"nickname": "LB",
"first_name": "Lynn",
"last_name": "Braun",
"grade": "9th Grade",
"school_name": "JFK High School",
"about_me": "I'm a cool sophomore that's in to Poggs.",
"name": "LB Braun",
"avatar_url": "https://zeumo-staging-2.s3.amazonaws.com/uploads/student/avatar/32/polaroid_avatar.jpg?1374245357",