Skip to content

Instantly share code, notes, and snippets.

@spllr
spllr / writing-ruby-gems-for-rubymotion.md
Created June 19, 2012 13:16
Writing Ruby gems for RubyMotion by Laurent Sansonetti

Writing Ruby gems for RubyMotion

Laurent Sansonetti

RubyMotion projects can be extended through the use of RubyGems, the Ruby de-facto packaging system. This article will cover how to write RubyMotion-specific gems.

This article was inspired by Create gems for RubyMotion, by Francis Chong.

Getting started

@kurenn
kurenn / gist:4421177
Last active March 29, 2017 21:16
This gist shows how to make a polymorphic association for users in rails which have an specific role, such as Member, Admin...works with devise
##Userable
module Userable
def self.included(base)
base.has_one :user, :as => :userable, :dependent => :destroy, :autosave => true
base.validate :user_must_be_valid
base.alias_method_chain :user, :autobuild
base.extend ClassMethods
base.define_user_accessors
end
@justin808
justin808 / Rakefile
Last active October 21, 2023 16:15
Rake tasks to rename Octopress posts to correspond to metadata, for org-mode as well. In Octopress, the meta is used for the blog post date.
org_posts_dir = "org_posts" # directory under source
# From http://www.ewal.net/2012/09/08/octopress-customizations/
# Modified to have default flag of true to include drafts
desc "Rename files in the posts directory if the filename does not match the post date in the YAML front matter"
task :rename_posts do
rename_posts_in_dir "#{source_dir}/#{posts_dir}", "markdown"
# remove next line if you're you're not using org-mode
rename_posts_in_dir "#{source_dir}/#{org_posts_dir}", "org"
@rjsamson
rjsamson / Rakefile
Created May 27, 2013 01:50
Example Rubymotion menubar app
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project/template/osx'
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'MenubarApp'
app.info_plist['NSUIElement'] = 1
end
@nixpulvis
nixpulvis / term_size.rb
Last active October 18, 2017 11:50
Get the terminal window size. Not in a bullshit ENV dependent manor.
# From the tty_ioctl man page in Linux.
#
# TIOCGWINSZ struct winsize *argp
# Get window size.
#
# TIOCSWINSZ const struct winsize *argp
# Set window size.
#
# The struct used by these ioctls is defined as
#
@garbados
garbados / player.rb
Last active January 2, 2016 12:39
Solution to ryanb/ruby-warrior intermediate difficulty, on epic.
## PERFORMANCE (1/7/13)
#
# CONGRATULATIONS! You have climbed to the top of the tower and rescued the fair maiden Ruby.
# Your average grade for this tower is: A
#
# Level 1: S
# Level 2: A
# Level 3: A
# Level 4: B
# Level 5: A
@v2keener
v2keener / tampermonkey-basic-injection-w-jQuery.js.sublime-snippet
Last active April 1, 2016 08:26
Snippet: Base TamperMonkey injection script with jQuery via Google APIs
// ==UserScript==
// @name ${1:Some fancy name}
// @namespace ${2:https://gist.github.com/9665787}
// @version 0.1
// @description ${3:Some description}
// @match /* ALLOW TAMPERMONKEY TO FILL THIS IN *OR* COPY FROM TAMPERMONKEY */
// @copyright 2014+, ${4:Gustavo Keener}
// ==/UserScript==
// Add jQuery, unless it already exists
require 'non_digest_assets'
namespace :assets do
task :non_digested do
NonDigestAssets.new.generate
end
end
module LiquidPresenters
class Plan < SimpleDelegator
def to_liquid
@to_liquid ||= HashWithIndifferentAccess.new({
id: self.id,
name: self.name,
description: self.description,
status: self.status,
class_id: self.plan_class_id
})
@csoma
csoma / gist:de71e151607940d6e523
Last active December 22, 2015 17:08
Remove GitHub Wiki page elements before printing

GitHub Wiki updated Bookmarklet (Sep 2014)

Note: Will not work with Firefox, see bug #866522

Wiki - Hides extra panels:


javascript:(function(e,a,g,h,f,c,b,d)%7Bif(!(f=e.jQuery)%7C%7Cg%3Ef.fn.jquery%7C%7Ch(f))%7Bc=a.createElement(%22script%22);c.type=%22text/javascript%22;c.src=%22https://ajax.googleapis.com/ajax/libs/jquery/%22+g+%22/jquery.min.js%22;c.onload=c.onreadystatechange=function()%7Bif(!b&&(!(d=this.readyState)%7C%7Cd==%22loaded%22%7C%7Cd==%22complete%22))%7Bh((f=e.jQuery).noConflict(1),b=1);f(c).remove()%7D%7D;a.documentElement.childNodes%5B0%5D.appendChild(c)%7D%7D)(window,document,%221.3.2%22,function($,L)%7B$('%23header,%20.pagehead,%20.breadcrumb,%20.commit,%20.meta,%20%23footer,%20%23footer-push,%20.wiki-actions,%20%23last-edit,%20.actions,%20.header,%20%23wiki-rightbar,%20.gh-header-actions,%20.sunken-menu-contents,%20.site-footer').remove();%20$('%23files,%20.file').css(%7B%22background%22:%22none%22,%20%22border%22:%22none%22%7D