Skip to content

Instantly share code, notes, and snippets.

View momolog's full-sized avatar

Alexander Presber momolog

View GitHub Profile
require 'rubygems'
require 'right_aws'
aws_access_key_id = 'YOUR AMAZON ACCESS KEY'
aws_secret_access_key = 'YOUR AMAZON SECRET ACCESS KEY'
source_bucket = 'SOURCE BUCKET NAME'
target_bucket = 'TARGET BUCKET NAME'
prefixes = [PATH_PREFIX1, PATH_PREFIX2, ...]
s3 = RightAws::S3Interface.new(aws_access_key_id, aws_secret_access_key)
@momolog
momolog / hrl_live_iframe
Created August 22, 2011 15:39
HTML for HRL live
<iframe frameborder="0" scrolling="no" width="100%" height="250" src="http://humanrightslogo.net/voting_widget"></iframe>
@momolog
momolog / hrl_staging_iframe
Created August 22, 2011 15:41
HTML for HRL staging
<iframe frameborder="0" scrolling="no" width="100%" height="250" src="http://hrl.staging.jovoto.net/voting_widget"></iframe>
@momolog
momolog / gist:1299337
Created October 19, 2011 19:09
View Before
<div id="profile">
<%= link_to_if @user.url.present?, image_tag("avatars/#{avatar_name(@user)}", class: "avatar"), @user.url %>
<h1><%= link_to_if @user.url.present?, (@user.full_name.present? ? @user.full_name : @user.username), @user.url %></h1>
<dl>
<dt>Username:</dt>
<dd><%= @user.username %></dd>
<dt>Member Since:</dt>
<dd><%= @user.member_since %></dd>
<dt>Website:</dt>
<dd>
@momolog
momolog / gist:1299342
Created October 19, 2011 19:10
View After
<div id="profile">
<%= @user.avatar %>
<h1><%= @user.linked_name %></h1>
<dl>
<dt>Username:</dt>
<dd><%= @user.username %></dd>
<dt>Member Since:</dt>
<dd><%= @user.member_since %></dd>
<dt>Website:</dt>
<dd><%= @user.website %></dd>
@momolog
momolog / gist:1299377
Created October 19, 2011 19:20
View After Hamlified
#profile
= @user.avatar
%h1= @user.linked_name
%dl
%dt Username:
%dd= @user.username
%dt Member Since:
%dd= @user.member_since
%dt Website:
%dd= @user.website
@momolog
momolog / simply_reliable
Created January 9, 2012 16:40
Aljoschas simply countable
// show tipsy with remaining characters
$('[data-maxlen]')
.tipsy({gravity: 'e', trigger: 'focus', html: true})
.each(function(){
var el = $(this);
el.data('doUpdateTitle', function(){
var len = el.val().length;
var remaining = el.data('maxlen')-len;
el.attr('title', '<span class="'+(remaining<0 ? 'red' : '')+'">Verbleibende Zeichen: '+remaining+'</span>').tipsy('hide').tipsy('show');·
return len;
@momolog
momolog / gist:2225454
Created March 28, 2012 11:08
run jquery functions on selected elements on newly inserted nodes
<html>
<head>
<script src="jquery.js" ></script>
<script>
$(function(){
$('body').on('DOMNodeInserted', function(){
$(event.target).find('.color').css({
'background-color': ('00000'+(Math.random()*(1<<24)|0).toString(16)).slice(-6)
});
@momolog
momolog / nested.rb
Created March 29, 2012 10:06
"valid" action - nested
def valid
if code = Code.find_by_value(params[:id])
unless code.used?
respond_with :valid => true
else
respond_with :valid => false, :reason => 'used'
end
else
respond_with :valid => false, :reason => 'unknown'
end
@momolog
momolog / throw-catch.rb
Created March 29, 2012 10:07
"valid" action - throw-catch
def valid
failure = catch :fail do
code = Code.find_by_value(params[:id]) or throw(:fail, 'unknown')
code.unused? or throw(:fail, 'used')
nil
end
respond_with({:valid => !failure}.merge(failure ? {:reason => failure}: {}))
end