Skip to content

Instantly share code, notes, and snippets.

View abitdodgy's full-sized avatar
😃
Out to lunch!

Mohamad El-Husseini abitdodgy

😃
Out to lunch!
View GitHub Profile
@kreeger
kreeger / MarkdownOnCocoaTouch.md
Created October 25, 2012 16:32
Displaying Markdown on Cocoa Touch.

In writing my first iOS app, I found myself reaching out in a few areas of self-discovery regarding the Cocoa Touch framework and what it's capable of, especially in how it compares to Ruby and it's standard library (which is what I've been used to for the past few years of my life). I've grown to love Ruby mixins and monkey-patching, and was delighted to learn that Objective-C has something quite similar: categories. ClassName+CategoryName.{h,m} is all you need, and you can define new class/static and instance methods on an Objective-C class.

One of my other strong preferences is for the Markdown format, and thus I snagged one of the more popular C-based implementations of Markdown (named [Sundown][sun]) and wrote a category around UIWebView for effortlessly displaying a parsed file. This was all made possible in the first place by [an awesome post on Stack Overflow][sta] on using Sundown with Objective-C.

//
//  UIWebView+Markdown.h
//

#import <UIKit/UIKit.h>
anonymous
anonymous / my.css
Created October 17, 2015 22:49
CSS Gradient Animation
background: linear-gradient(270deg, #28b691, #d0b93c);
background-size: 400% 400%;
-webkit-animation: AnimationName 33s ease infinite;
-moz-animation: AnimationName 33s ease infinite;
-o-animation: AnimationName 33s ease infinite;
animation: AnimationName 33s ease infinite;
@-webkit-keyframes AnimationName {
    0%{background-position:0% 50%}
    50%{background-position:100% 50%}
    100%{background-position:0% 50%}
@jwreagor
jwreagor / assert_queue.rb
Last active December 15, 2015 04:59
AssertQueue: An abstraction for testing background queuing in MiniTest, specifically Sidekiq
module AssertQueue
def assert_queued(klass, args)
assert AssertQueue.includes?(klass, args), "Queue should contain #{klass} with args #{args.inspect}\n#{AssertQueue.queue.inspect}"
end
def self.included(base)
Sidekiq::Client.instance_eval do
def push(item)
AssertQueue.queue.push item
@seyhunak
seyhunak / bootstrap-confirmation.js
Created June 28, 2013 09:08
Twitter Bootstrap Confirmation Dialog Modal - Rails UJS
$.rails.allowAction = function(link) {
if (!link.attr('data-confirm')) {
return true;
}
$.rails.showConfirmDialog(link);
return false;
};
$.rails.confirmed = function(link) {
link.removeAttr('data-confirm');
@kidpollo
kidpollo / gist:5287007
Created April 1, 2013 19:17
Punditry on scopes

Pundit has a helper method policy_scope that can be used in controllers and views that basicaly a class finder. It is equivalent to:

@posts = policy_scope(Post)
@posts = PostPolicy::Scope.new(current_user, Post).resolve

Using the helper is a nice approach because you dont have to remember what Scope class you need. This is all fine and well on a world where the app is single teanant or the auth logic to reslove scopes needs no other context but the user and the resource that is being requested.

In our world almost all requests are nested under a company context and require a current user to determine membership role to present certain data.

@ggilder
ggilder / linked_stack.rb
Created August 1, 2012 07:03
Linked List Ruby implementation
require 'minitest/autorun'
class LinkedStack
class ElementNotFound < RuntimeError; end
attr_reader :head
def empty?
@head == nil
end
@Darep
Darep / item.rb
Created January 24, 2013 19:15
Ruby on Rails concern example: making an ActiveRecord item sortable. Adapted from: http://say26.com/show-us-your-production-code-1-concerns
# app/models/item.rb
require 'concerns/sortable'
class Item < ActiveRecord::Base
include Sortable
attr_accessible :title
end
$.rails.allowAction = function(link) {
if (!link.attr('data-confirm')) {
return true;
}
$.rails.showConfirmDialog(link);
return false;
};
$.rails.confirmed = function(link) {
link.removeAttr('data-confirm');
@jorilallo
jorilallo / Github's usage of the showdown.js in example
Created October 13, 2011 01:16
Showdown.js with GitHub Flavored Markdown
$(function() {
var converter = new Showdown.converter();
$("#user_input").keyup(function(){
var txt = $("#user_input").val();
var html = converter.makeHtml(txt);
$("#result").html(html)
$("#html_result").val(html.replace(/>/g, ">\n").replace(/</g, "\n<").replace(/\n{2,}/g, "\n\n"));
});
var sample = "#### Underscores\nthis should have _emphasis_\nthis_should_not\n_nor_should_this\n\n\