Skip to content

Instantly share code, notes, and snippets.

View maca's full-sized avatar

Macario Ortega maca

View GitHub Profile
require 'sequel'
require 'sequel/extensions/migration'
DB = Sequel.sqlite
Sequel.migration do
change do
create_table(:classes, :ignore_index_errors => true) do
primary_key :cid
end
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
@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 / 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
@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
--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/
class Proc
def in_discomfort?; :me; end
end
you_are = you =
->(you) do
self.inspect until true
@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 %>">