Skip to content

Instantly share code, notes, and snippets.

View thelastinuit's full-sized avatar
I don't know love. I was built to protect not to love.

loving marshmallow thelastinuit

I don't know love. I was built to protect not to love.
View GitHub Profile
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render json: user.as_json(auth_token: user.authentication_token, email: user.email), status: :created
return
else
@thelastinuit
thelastinuit / Better API
Last active August 29, 2015 14:02
Better API
# http://api.awesomeurl.com/generalresource.json
# http://api.awesomeurl.com/v1/resource.json
# http://api.awesomeurl.com/v2/resource.json
namespace :api, :path => "", :constraints => {:subdomain => "api"}, :defaults => {:format => :json} do
resources :generalresource
namespace :v1 do
resources :resource
end
@thelastinuit
thelastinuit / ObserveFrame
Created July 4, 2014 06:34
Observe Frame
[RACObserve(self.view, frame) subscribeNext:^(NSNumber *rect) {
NSLog(@"position y: %f", rect.CGRectValue.origin.y);
}];
@thelastinuit
thelastinuit / 0_reuse_code.js
Created July 17, 2014 00:10
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@thelastinuit
thelastinuit / doubletapcell
Created July 23, 2014 20:54
Double tap cell detection
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
for (UITouch* touch in touches) {
if (touch.tapCount == 2) {
CGPoint where = [touch locationInView:self];
NSIndexPath* ip = [self indexPathForRowAtPoint:where];
NSLog(@"double clicked index path: %@", ip);
}
}
[super touchesEnded:touches withEvent:event];
@thelastinuit
thelastinuit / data_format.rb
Created July 24, 2014 00:09
Date & Time Formatter Rails
# Date
# ----------------------------
#Date::DATE_FORMATS[:default] = "%Y-%m-%d" # 2013-11-03
#Date::DATE_FORMATS[:default] = "&proc" # November 3rd, 2013
#Date::DATE_FORMATS[:default] = "%B %e, %Y" # November 3, 2013
#Date::DATE_FORMATS[:default] = "%e %b %Y" # 3 Nov 2013
#Date::DATE_FORMATS[:default] = "%Y%m%d" # 20131103
#Date::DATE_FORMATS[:default] = "%e %b" # 3 Nov
#Date::DATE_FORMATS[:default] = "" # custom

Objective-C Coding Convention and Best Practices

Most of these guidelines are to match Apple's documentation and community-accepted best practices. Some are derived some personal preference. This document aims to set a standard way of doing things so everyone can do things the same way. If there is something you are not particularly fond of, it is encouraged to do it anyway to be consistent with everyone else.

This document is mainly targeted toward iOS development, but definitely applies to Mac as well.

Operators

NSString *foo = @"bar";

Here's what you get.

Some CoffeeScript (verbosely commented for clarity)

# Override Rails handling of confirmation

$.rails.allowAction = (element) ->
  # The message is something like "Are you sure?"
  message = element.data('confirm')
#!/usr/bin/env ruby
require "openssl"
require 'digest/sha2'
require 'base64'
# We use the AES 256 bit cipher-block chaining symetric encryption
alg = "AES-256-CBC"
# We want a 256 bit key symetric key based on some passphrase
digest = Digest::SHA256.new
# create the template
template = PageOfflineTemplate.new
template.quote = quote
template.pages = quote.build_pages
# Here I render a template with layout to a string then a PDF
pdf = PDFKit.new template.render_to_string(:template=>"quotes/review.html.haml")