Skip to content

Instantly share code, notes, and snippets.

View seyhunak's full-sized avatar
🏆
Winning The Life

Seyhun Akyürek seyhunak

🏆
Winning The Life
View GitHub Profile
@seyhunak
seyhunak / EmployeeApiService.swift
Last active November 9, 2023 08:02
Swift 5 - MVVM - ViewController, ViewModel, Model, Datasource, Webservice
import Foundation
class APIService : NSObject {
private let sourcesURL = URL(string: "http://dummy.restapiexample.com/api/v1/employees")!
func apiToGetEmployeeData(completion : @escaping (Employees) -> ()){
URLSession.shared.dataTask(with: sourcesURL) { (data, urlResponse, error) in
if let data = data {
let jsonDecoder = JSONDecoder()
let empData = try! jsonDecoder.decode(Employees.self, from: data)
@seyhunak
seyhunak / http_requests.swift
Created July 16, 2014 15:07
HTTP Requests - Swift
func JSONParseDict(jsonString:String) -> Dictionary<String, AnyObject> {
var e: NSError?
var data: NSData = jsonString.dataUsingEncoding(
NSUTF8StringEncoding)
var jsonObj = NSJSONSerialization.JSONObjectWithData(
data,
options: NSJSONReadingOptions(0),
error: &e) as Dictionary<String, AnyObject>
if e {
return Dictionary<String, AnyObject>()
@seyhunak
seyhunak / apache_bench.sh
Last active July 5, 2023 17:02
Rails - Apache Bench - Load Testing (if Devise Sign-in Required)
1.
LOGIN_PAGE=http://localhost/users/sign_in
curl --cookie-jar cookie_file $LOGIN_PAGE | grep csrf-token
2.
<meta content="csrf-token" name="csrf-token" />
@seyhunak
seyhunak / seeds.rb
Created December 7, 2013 14:54
Rails - Import SQL file as seed
unless Rails.env.production?
connection = ActiveRecord::Base.connection
connection.tables.each do |table|
connection.execute("TRUNCATE #{table}") unless table == "schema_migrations"
end
sql = File.read('db/import.sql')
statements = sql.split(/;$/)
statements.pop
@seyhunak
seyhunak / devise_helper.rb
Created September 16, 2013 10:50
Devise Error Messages Twitter Bootstrap style
# /app/helpers/devise_helper.rb
module DeviseHelper
def devise_error_messages!
return '' if resource.errors.empty?
messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
sentence = I18n.t('errors.messages.not_saved',
count: resource.errors.count,
resource: resource.class.model_name.human.downcase)
@seyhunak
seyhunak / mini_magick.rb
Created September 9, 2013 13:30
How to add a text caption to an image with MiniMagick and Ruby
require 'rubygems'
require 'mini_magick'
img = MiniMagick::Image.from_file("jpeg.jpg")
img.combine_options do |c|
c.gravity 'Southwest'
c.draw 'text 10,10 "whatever"'
c.font '-*-helvetica-*-r-*-*-18-*-*-*-*-*-*-2'
c.fill("#FFFFFF")
end
@seyhunak
seyhunak / git-flow.md
Last active May 9, 2022 12:13
Git Flow - Cheatsheet

Git-Flow

Initialize a Repository for git-flow

git flow init -d

(Omit -d if you want to select values other than the defaults.)

Features

@seyhunak
seyhunak / view.rb
Created October 29, 2012 22:44
Custom confirmation dialog in Rails
# Coffeescript
$.rails.allowAction = (link) ->
return true unless link.attr('data-confirm')
$.rails.showConfirmDialog(link) # look bellow for implementations
false # always stops the action since code runs asynchronously
$.rails.confirmed = (link) ->
link.removeAttr('data-confirm')
link.trigger('click.rails')
@seyhunak
seyhunak / global.css.scss
Created March 14, 2014 11:51
SASS (Bourbon + Bourbon Neat) - Variables, Base, Typography classes
// Place all the styles related to the welcome controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
@import "bourbon";
@import "neat";
/*
* Variables
*/
select (case when tile = 50 then 'Median' when tile = 95 then '95%' else '5%' end) as tile
, app_display_version
, max(cast( ROUND(duration/1000)/1000 as numeric) ) max_duration_s
, min(cast( ROUND(duration/1000)/1000 as numeric) ) min_duration_s
from (
select
trace_info.duration_us duration
, ntile(100) over (partition by (app_display_version) order by trace_info.duration_us) tile
, app_display_version