Skip to content

Instantly share code, notes, and snippets.

View maca's full-sized avatar

Macario Ortega maca

View GitHub Profile
require 'sinatra'
require 'pathname'
get %r{^(?!/files)(.+$)} do |path|
dir = './public/files' + path
pass unless File.exists?(dir)
@links = Dir[ dir + '*' ].map do |file|
url = file.gsub %r{^\./public}, ''
file_link( File.directory?( file ) ? url.gsub( %r{^/files}, '' ) + '/' : url )
end
class Proc
def in_discomfort?; :me; end
end
you_are = you =
->(you) do
self.inspect until true
@maca
maca / das_download.rb
Created February 11, 2012 09:08
Script to download all Destroy All Software screencasts, account needed
#! /usr/bin/env ruby
# usage:
# $ das_download.rb email password [download_directory]
require 'mechanize'
# gem 'mechanize-progressbar'
email = ARGV[0] or raise('Please provide the email address for your account')
password = ARGV[1] or raise('Please provide the password for your account')
path = ARGV[2] || './'
@maca
maca / jquery.xhr.uploads.js
Created March 6, 2012 02:28
jquery.xhr.uploads.js
/*
* jQuery XHR upload plugin
* http://github.com/maca
*
* Copyright 2011, Macario Ortega
* Dual licensed under the MIT or GPL Version 2 licenses.
*
*/
(function($){
@maca
maca / jquery.xhr.uploads.js
Created March 6, 2012 02:28
jquery.xhr.uploads.js
/*
* jQuery XHR upload plugin
* http://github.com/maca
*
* Copyright 2011, Macario Ortega
* Dual licensed under the MIT or GPL Version 2 licenses.
*
*/
(function($){
@maca
maca / example.erb.html
Created July 12, 2012 08:15
Jquery plugin for adding and removing nested records (Rails accepts nested attributes for)
<!-- Sorry, this example is with formtastic but I think it would work the same with vanilla rails form helpers -->
<%= semantic_form_for @survey do |form| %>
<fieldset class="nested_models answers" data-association="answers">
<%- form.object.answers.build %>
<%= form.semantic_fields_for :answers do |answer| %>
<%- record = answer.object %>
<fieldset class="<%= record.new_record? ? :new : nil %>">
@maca
maca / snapshot-backup.sh
Created July 20, 2012 20:30
Script to emulate time machine snapshot based backup.
#!/bin/bash
## my own rsync-based snapshot-style backup procedure
## (cc) marcio rps AT gmail.com
## modified by github.com/maca
lock=/tmp/snapshot-lock
if [ -f $lock ] ; then
echo "snapshot: a lock file seems to exist $lock"
exit
fi
--langdef=coffee
--langmap=coffee:.coffee
--regex-coffee=/(^|=[ \t])*class ([A-Za-z]+\.)*([A-Za-z]+)( extends [A-Za-z_.]+)?$/\3/c,class/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?@?([A-Za-z_.]+):.*[-=]>.*$/\3/m,method/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?([A-Za-z_.]+)[ \t]+=.*[-=]>.*$/\3/f,function/
--regex-coffee=/^[ \t]*([A-Za-z_.]+)[ \t]+=[^->\n]*$/\1/v,variable/
--regex-coffee=/^[ \t]*@([A-Za-z_.]+)[ \t]+=[^->\n]*$/\1/f,field/
--regex-coffee=/^[ \t]*@([A-Za-z_.]+):[^->\n]*$/\1/f,static field/
--regex-coffee=/^[ \t]*([A-Za-z_.]+):[^->\n]*$/\1/f,field/
@maca
maca / jquery.xhr-uploads.js
Last active December 15, 2015 21:09
jQuery xhr uploads plugin.
/*
* jQuery XHR upload plugin
* http://github.com/maca
*
* Copyright 2011, Macario Ortega
* Dual licensed under the MIT or GPL Version 2 licenses.
*
*/
(function($){
@maca
maca / template.rb
Last active December 17, 2015 20:38
require 'bundler'
run "echo TODO > README.rdoc"
wants_bootstrap = yes? 'Do you want to use bootstrap?'
wants_devise = yes? 'Do you want to use devise?'
if wants_devise
devise_model = ask 'What would you like your devise model to be?'
devise_model_fields = ask 'Yo can optionally provide additional params for the devise model (eg. name:string)'
end