Skip to content

Instantly share code, notes, and snippets.

View nauman's full-sized avatar
🚀
Need MVP? book me in https://tidycal.com/nauman

Nauman Tariq nauman

🚀
Need MVP? book me in https://tidycal.com/nauman
View GitHub Profile
@doublerebel
doublerebel / tiger-swipe-nav.coffee
Created September 26, 2012 21:19
Example of Swipe Navigation with Tiger on Titanium Mobile
Tiger = require '/lib/tiger'
Route = require '/lib/tiger.route'
class BaseView extends Tiger.Window
close: ->
direction = Tiger.Route.direction
left = if direction is 'prev' then '-100%' else '100%'
@animate {left: left, duration: 400}, @element.close
@cedricdekimpe
cedricdekimpe / application.js
Created May 29, 2012 09:27
How-to override window.confirm() dialog with Rails 3 and bootbox.js
//= require bootbox.min
@ordinaryzelig
ordinaryzelig / minitest_spec_expectations.md
Last active March 23, 2025 21:22
How to write MiniTest::Spec expectations

I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").

Understanding MiniTest::Expectations

Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):

# minitest/spec.rb

module MiniTest::Expectations
@cdmwebs
cdmwebs / friendly_urls.markdown
Created September 11, 2011 15:50 — forked from jcasimir/friendly_urls.markdown
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@rtomayko
rtomayko / optparse-template.rb
Last active June 3, 2023 03:16
Ruby optparse template
#!/usr/bin/env ruby
#/ Usage: <progname> [options]...
#/ How does this script make my life easier?
# ** Tip: use #/ lines to define the --help usage message.
$stderr.sync = true
require 'optparse'
# default options
flag = false
option = "default value"
@aaronksaunders
aaronksaunders / app.js
Created June 23, 2011 05:00
use only one instance of the httpClient?
var serviceList = [];
var xhr;
var tmpSvc = fetchServicesByProfile(Titanium.UI.currentWindow.profileid);
for(i=0;i<tmpSvc.length;i++)
{
//Populate serviceList array.
}
function processServiceList(index)
@snuggs
snuggs / .vimrc
Last active April 4, 2021 05:59
VIM "$ mkdir ~/.tmp # ensure directory exists first
set encoding=utf-8
" Author: Ahmid-Ra (github.com/snuggs)
" Screencasts: http://vimcasts.org
" Gist: https://gist.github.com/snuggs/612093
" Tutorial: http://learnvimscriptthehardway.stevelosh.com
@tomlea
tomlea / proxy.rb
Created October 11, 2009 21:11
Rack Middleware to proxy requests to a remote server. This is usefull for proxying AJAX request to remote services.
require "net/http"
require "enumerator"
# Example Usage:
#
# use Rack::Proxy do |req|
# if req.path =~ %r{^/remote/service.php$}
# URI.parse("http://remote-service-provider.com/service-end-point.php?#{req.query}")
# end
# end
@henrik
henrik / hash_deep_diff.rb
Created July 14, 2009 08:38
Recursively diff two Ruby hashes.
# Recursively diff two hashes, showing only the differing values.
# By Henrik Nyh <http://henrik.nyh.se> 2009-07-14 under the MIT license.
#
# Example:
#
# a = {
# "same" => "same",
# "diff" => "a",
# "only a" => "a",
# "nest" => {