Skip to content

Instantly share code, notes, and snippets.

@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
#
@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
@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"
@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
@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

@myronmarston
myronmarston / ways_to_use_vcr.rb
Created April 13, 2012 15:00
Ways to use VCR for a request made by a let block
# 1) Use VCR.use_cassette in your let block. This will use
# the cassette just for requests made by creating bar, not
# for anything else in your test.
let(:foo) { VCR.use_cassette("foo") { create(:bar) } }
it "uses foo" do
foo
end
# 2) Wrap the it block that uses #foo in VCR.use_cassette.
@dominic
dominic / gist:1873044
Created February 21, 2012 02:14
MacRuby App Store manual deployment steps

Submitting to the App Store

First, install Developer certs from Apple's Developer portal

To Build the Application:

  • Select "Your App" from your Scheme menu, NOT "Deployment"
  • Select Product > Archive to build for Release
  • Once completed, the Organizer window will open
  • Select your recent build and press the "Validate" button - make sure this passes!
@jasonrudolph
jasonrudolph / git-branches-by-commit-date.sh
Created February 12, 2012 20:40
List remote Git branches and the last commit date for each branch. Sort by most recent commit date.
# Credit http://stackoverflow.com/a/2514279
for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ci %cr" $branch | head -n 1` \\t$branch; done | sort -r
@andredublin
andredublin / gist:1441363
Created December 7, 2011 03:46
activerecord rpsec pg error
Failure/Error: Unable to find matching line from backtrace
ActiveRecord::StatementInvalid:
PGError: ERROR: syntax error at or near "IDENTITY"
LINE 1: TRUNCATE TABLE RESTART IDENTITY CASCADE;
^
: TRUNCATE TABLE RESTART IDENTITY CASCADE;
@kylefox
kylefox / liquid-mode.js
Created November 11, 2011 00:02
Liquid syntax highlighting for CodeMirror.
/*
This overlay provides a 'liquid' mode to the excellent CodeMirror editor (http://codemirror.net/).
Add something like this to your CSS:
.cm-liquid-tag {
color: #32273f;
background: #ead9ff;
}
.cm-liquid-variable {