Skip to content

Instantly share code, notes, and snippets.

View ayrton's full-sized avatar

Ayrton ayrton

View GitHub Profile
@ayrton
ayrton / svg_sprites.md
Created September 21, 2023 09:55 — forked from darsain/svg_sprites.md
How to use SVG sprites in img[src] and css backgrounds

To make this work in CSS:

background: url('images.svg#chart');

or img:

<img src="images.svg#chart">
class ApplicationController < ActionController::Base
include EtagWithLayout
end
@ayrton
ayrton / stateless-component.js
Created October 11, 2015 14:26
Stateless React component
import PureRenderMixin from 'react-addons-pure-render-mixin';
import React from 'react';
import Audio from './Audio';
import Image from './Image';
import MediaRecord from 'ph/records/MediaRecord';
import PostRecord from 'ph/records/PostRecord';
import Video from './Video';
import {MEDIA_TYPE_AUDIO, MEDIA_TYPE_IMAGE, MEDIA_TYPE_VIDEO} from 'ph/constants/MediaConstants';
# Single object
<%= render partial: 'thumbnail', object: video, as: :video %>
<%= render partial: 'thumbnail', locals: { video: video } %>
<%= render 'thumbnail', video: video %>
# Collection
<%= render partial: 'thumbnail', collection: videos, as: :video %>
@ayrton
ayrton / gist:5929299
Last active December 19, 2015 08:59 — forked from jordelver/gist:5806460

Sharing files using netcat

The receiver

nc -l 5566 > data-dump.sql

Listen on port 5566 and redirect output to data-dump.sql

The sender

@ayrton
ayrton / taggable.rb
Last active September 29, 2020 20:42
Testing Active Support concerns with rspec in isolation. See first comment for more information.
module Taggable
extend ActiveSupport::Concern
included do
attr_accessible :tags
after_save :set_tags
after_destroy :unset_tags
end
class Duration
attr_accessor :duration
def initialize(string)
@duration = string
end
def to_i
value_units.map(&:to_i).reduce(&:+)
end
@ayrton
ayrton / cards.coffee
Created August 22, 2012 11:35
Coffeescript (after) vs. JavaScript (before)
class Card
constructor: (selector) ->
@$container = $('.cards')
@$element = @$container.find(selector)
@$text = @$element.find('.card-menu li:first-child a span')
toggleClass: ->
@$element.toggleClass('is-favorited')
changeText: ->
cardText = if @$element.favorited then 'Unfavorite' else 'Favorite'
@$text.text(cardText)
@ayrton
ayrton / ajax.coffee
Created April 10, 2012 14:50
TypeError
twfbCounters = ->
$twitterFacebook = $('#twfb')
$.ajax {
url: 'http://api.twitter.com/1/users/show.json',
data: 'screen_name=zeptojs',
dataType: 'jsonp'
success: (data, status, xhr) ->
$twitterFacebook.html(data.followers_count)
error: (xhr, errorType, error) ->
@ayrton
ayrton / gist:2292579
Created April 3, 2012 14:45
and & &&
@error = :invalid_type and return if (type = params[:type]) and (type != :iphone && type != :android)
# exactly the same as: (if prefer the former)
if type = params[:type] and (type != :iphone && type != :android)
@error = :invalid_type
return
end
# or