Skip to content

Instantly share code, notes, and snippets.

View truemagic-coder's full-sized avatar
:octocat:
Working

TrueMagic truemagic-coder

:octocat:
Working
View GitHub Profile
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@house9
house9 / Simple.Data.MongoDB.openMongo.cs
Created May 3, 2011 23:31
Simple.Data with MongoDB
using Simple.Data;
using Simple.Data.MongoDB;
// connect
dynamic db = Database.Opener.OpenMongo("mongodb://localhost:27017/myDB");
// insert
dynamic user = new ExpandoObject();
user.FirstName = "Joe";
user.LastName = "Smith";
@runemadsen
runemadsen / description.markdown
Created September 26, 2011 15:23
Reverse polymorphic associations in Rails

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.

@dkubb
dkubb / .gitignore
Created December 5, 2011 18:26
Test Feedzirra w/VCR using an HTTP proxy
cassettes
@tdegrunt
tdegrunt / reg_exp_validator.coffee
Created January 14, 2012 16:08
RegExp Validator for batman.js (RegExpValidator)
class RegExpValidator extends Batman.Validator
@options 'with', 'message'
validateEach: (errors, record, key, callback) ->
value = record.get(key)
if !value? || !value.match(@options.with)
errors.add key, Batman.translate('errors.format', {attribute: key, message: @options.message})
callback()
Batman.Validators.push RegExpValidator
<?php
/*
Plugin Name: Test
*/
class My_Like_Button {
function __construct()
{
$this->hooks();
}
@asavartsov
asavartsov / sweeping.rb
Created March 17, 2012 10:52
Cache Sweeper for Mongoid
# 2. Include Sweeping module in your controller(s) to have cache_sweeper
# method to be avaliable, or right in ApplicationController so it will be
# available in all controllers inheriting from it.
class ApplicationController < ActionController::Base
include ActionController::Caching::Sweeping
# ...
end
@ShirtlessKirk
ShirtlessKirk / luhn.js
Last active May 17, 2024 08:05
Luhn validation algorithm
/**
* Luhn algorithm in JavaScript: validate credit card number supplied as string of numbers
* @author ShirtlessKirk. Copyright (c) 2012.
* @license WTFPL (http://www.wtfpl.net/txt/copying)
*/
var luhnChk = (function (arr) {
return function (ccNum) {
var
len = ccNum.length,
bit = 1,
@mmacedo
mmacedo / gist:2475470
Created April 24, 2012 01:51 — forked from inossidabile/gist:1582000
JQuery ajax upload.onprogress binding
$.ajax
# ...
beforeSend: (xhr) =>
if xhr.upload?
xhr.upload.onprogress = =>
console.log arguments...
@domenic
domenic / oauth2-restify.js
Created June 2, 2012 06:25
OAuth2 with Restify
"use strict";
var restify = require("restify");
var users = require("./users");
// The users module will have a getAuthorizationFromAccessTokenAsync promise-returning export. (Convert to callbacks if you wish).
// It rejects in cause of not authorized, or fulfills with a { scope, customerId } object if the user is authorized.
// The scope property indicates which scopes the user corresponding to a given access token has.
module.exports = function authPlugin(serverRequest, serverResponse, next) {