Skip to content

Instantly share code, notes, and snippets.

View ahmetabdi's full-sized avatar
:shipit:

Ahmet ahmetabdi

:shipit:
View GitHub Profile
@ahmetabdi
ahmetabdi / gist:13337e6833d4d5b8ae0f
Last active February 20, 2016 22:39
Calculates the difference between two RGB Colour Values using Euclidean distance algorithm
r1 = 1.0
r2 = 0.95
g1 = 1.0
g2 = 1.0
b1 = 0.2
b2 = 0.1
# Euclidean distance
# =================================
# = Warped shadow for any CGLayer =
# =================================
def warpShadow(rect, offset)
size = rect.size
path = UIBezierPath.bezierPath
# Top/Right: ````|
path.moveToPoint([offset, offset])
path.addLineToPoint([size.width - offset, offset])
@ahmetabdi
ahmetabdi / gist:9932034
Created April 2, 2014 11:05
Validating Multiple Fields in Rails
validate :unique_organisation_entry
def unique_organisation_entry
matched_entry = Organisation.where(['LOWER(name) = LOWER(?) AND LOWER(company_no) = LOWER(?) AND LOWER(postcode) = LOWER(?)', self.name, self.company_no, self.postcode]).first
errors.add(:base, 'I know you think you\'re clever, but someone already submitted that one.') if matched_entry && (matched_entry.id != self.id)
end
### Show stack trace for 500 errors
### (adapted from https://gist.github.com/1079020)
# Given an application, yield to a block to handle exceptions
class ExceptionRaiserApp
def initialize(app)
@app = app
end
def call(env)
class IndexController < UITableViewController
def init
super.tap do
self.tabBarItem = UITabBarItem.alloc.initWithTitle('Index', rmq.image.resource('home'), tag: 1)
self.title = 'Index'
end
end
end
Rails.cache.fetch("cached_tweet", expires_in: 1.hour) do
Timeout::timeout(5) do
Built-in Atom packages (84)
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
iex(1)> Tmdb.Movie.popular
[page: 1,
results: [%{"adult" => false,
"backdrop_path" => "/xu9zaAevzQ5nnrsXN6JcahLnG4i.jpg", "id" => 157336,
"original_title" => "Interstellar", "popularity" => 34.1716910628099,
"poster_path" => "/nBNZadXqJSdt05SHLqgT0HuC5Gm.jpg",
iex(1)> Tmdb.Movie.popular[:results]
[%{"adult" => false, "backdrop_path" => "/xu9zaAevzQ5nnrsXN6JcahLnG4i.jpg",
"id" => 157336, "original_title" => "Interstellar",
"popularity" => 34.1716910628099,
"poster_path" => "/nBNZadXqJSdt05SHLqgT0HuC5Gm.jpg",
"release_date" => "2014-11-05", "title" => "Interstellar", "video" => false,
"vote_average" => 8.5, "vote_count" => 2009},
%{"adult" => false, "backdrop_path" => "/c1OSRvorPXvGtFka7mgV6Jcw6jd.jpg",
"id" => 168259, "original_title" => "Furious 7",
"popularity" => 29.8393594653136,
You can configure git to push to the current branch using the following command
git config --global push.default current
then just do
git push
this will push the code to your current branch.