Skip to content

Instantly share code, notes, and snippets.

@Chris927
Chris927 / log excerpt
Created May 27, 2011 13:29
adding refinery to rails 3.0.7 app, sign up / redirect issue
Started GET "/users/sign_up" for 127.0.0.1 at 2011-05-27 15:24:18 +0200
Processing by Devise::RegistrationsController#new as HTML
SQL (1.1ms) SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
SQL (0.3ms) SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
Page::Translation Load (0.2ms) SELECT page_id AS id FROM "page_translations" WHERE "page_translations"."locale" = 'en'
def chop(v, values)
ix = values.length / 2
m = values[ ix ]
return ix if v == m
return nil if values.length < 2
if v > m
ix + 1 + chop(v, values[ix+1..-1]) rescue nil
@Chris927
Chris927 / reverse.coffee
Created July 13, 2011 08:08
Reverse a string in CoffeeScript
reverse = (s) ->
if s.length < 2 then s else reverse(s[1..-1]) + s[0]
s = "Hello"
console.log "s=#{s}, s.reverse=#{reverse(s)}"
@Chris927
Chris927 / gist:1128612
Created August 5, 2011 21:53
How to install sparkleshare on Ubuntu 10.04
# add repos and update apt
sudo add-apt-repository ppa:git-core/ppa
sudo add-apt-repository ppa:warp10/sparkleshare
sudo apt-get update
# install it
sudo apt-get install sparkleshare
@Chris927
Chris927 / generic_repo.rb
Created August 21, 2011 09:51
Repository Ideas (DDD style) for Rails
module GenericRepo
def self.included(base)
base.class_eval do
extend ClassMethods
end
end
module ClassMethods
attr_accessor :model
def create(params)
@Chris927
Chris927 / second_generator.rb
Created August 28, 2011 19:27
Adding a second generator to a gem
require 'rails/generators/migration'
# must be placed in the gem's dir 'lib/generators/my_gem/second/second_generator.rb'
module MyGem
# TODO: this module tries to DRY up a bit, should be elsewhere in
# its own file
module MigrationGenerator
def self.included(base)
base.extend(ClassMethods)
@Chris927
Chris927 / dci_experiment.rb
Created February 6, 2012 09:28
DCI experiment, using the R82 domain
# the role
# TODO: should the class be named 'MatchCreator'? What the role does
# is independent of needs
module NeedToOtherNeedConnector
def connect_needs(from, to)
match = Match.new(:user => self, :from => from, :to => to)
end
end
# the context
@Chris927
Chris927 / test.html
Created March 9, 2012 07:05
HTML5 / pure javascript to post the 'modified date' when uploading a file
<!doctype html>
<html>
<head>
<title>Just testing...</title>
</head>
<body>
<script type="text/javascript">
function updateFile() {
var files = document.getElementById("uploadInput").files;
var nFiles = files.length;
@Chris927
Chris927 / demo.diff
Created April 23, 2012 15:51
Diff of the code changes we did in last week's session
diff --git a/grails-app/views/layouts/main.gsp b/grails-app/views/layouts/main.gsp
index 4e70434..8d3dcae 100644
--- a/grails-app/views/layouts/main.gsp
+++ b/grails-app/views/layouts/main.gsp
@@ -12,14 +12,23 @@
<link rel="shortcut icon" href="${resource(dir: 'images', file: 'favicon.ico')}" type="image/x-icon">
<link rel="apple-touch-icon" href="${resource(dir: 'images', file: 'apple-touch-icon.png')}">
<link rel="apple-touch-icon" sizes="114x114" href="${resource(dir: 'images', file: 'apple-touch-icon-retina.png')}">
+ <link rel="stylesheet" href="/todo/css/bootstrap.css" />
<!-- <link rel="stylesheet" href="${resource(dir: 'css', file: 'main.css')}" type="text/css"> -->
@Chris927
Chris927 / fileupload-experiment.html
Created April 24, 2012 15:04
Use programmatic file upload (via plugin) after asking questions to user
<!--
see also: https://github.com/blueimp/jQuery-File-Upload/issues/473
This didn't work with an 'old' version of the plugin, try the latest one.
Idea is to do file upload all programmatically, thus only sending files once user has confirmed what to do with the files.
-->
<div class="row">
<div class="span10">