Skip to content

Instantly share code, notes, and snippets.

Štefan Ľupták EskiMag

Block or report user

Report or block EskiMag

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@EskiMag
EskiMag / behaviour.ex
Last active Sep 5, 2019
Behaviour vs. Protocol in Elixir
View behaviour.ex
defmodule Counter do
@type t :: %__MODULE__{count: integer()}
defstruct count: 0
def transform(counter, %transformation_module{} = transformation) do
transformation_module.transform(counter, transformation)
end
end
defmodule Counter.Transformation do
View moje_riesenie.ex
#! /usr/bin/env elixir
ExUnit.start()
defmodule Ranges do
def run(indexes, length) do
ranges(indexes, length, nil, [])
end
# private
View FloatingViewController.swift
import UIKit
class FloatingButtonController: UIViewController {
private(set) var button: UIButton!
required init?(coder aDecoder: NSCoder) {
fatalError()
}
View gist:2502581
upstream gitlab {
server unix:/home/gitlab/gitlab/tmp/sockets/gitlab.socket;
}
server {
listen YOUR_SERVER_IP:80;
server_name gitlab.YOUR_DOMAIN.com;
root /home/gitlab/gitlab/public;
# individual nginx logs for this gitlab vhost
View gist:2502822
#! /bin/bash
### BEGIN INIT INFO
# Provides: gitlab
# Required-Start: $local_fs $remote_fs $network $syslog redis-server
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: GitLab git repository management
# Description: GitLab git repository management
### END INIT INFO
@EskiMag
EskiMag / NSRegularExpression-Example.m
Created Mar 11, 2011
Prints first match of text in parenthesis
View NSRegularExpression-Example.m
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"id=([0-9]+)" options:NSRegularExpressionCaseInsensitive error:&error];
NSTextCheckingResult *result = [regex firstMatchInString:str options:NSMatchingReportCompletion range:NSMakeRange(0, [str length])];
NSLog(@"%@", [str substringWithRange:[result rangeAtIndex:1]]); // prints 123 for "id=123"
View gist:845240
CGFloat width = 300;
// returns 15
[text sizeWithFont:[UIFont fontWithName:@"Helvetica" size:12.0] forWidth:width lineBreakMode:UILineBreakModeWordWrap].height;
// returns 60
[text sizeWithFont:[UIFont fontWithName:@"Helvetica" size:12.0] constrainedToSize:CGSizeMake(width, 100) lineBreakMode:UILineBreakModeWordWrap].height
@EskiMag
EskiMag / gist:805853
Created Feb 1, 2011
Cocoa vs. Rails method returning the end of current month
View gist:805853
- (NSDate *)endOfThisMonth {
NSDate *endOfMonth = [NSDate date];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *comp = [calendar components:(NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:[NSDate date]];
[comp setMonth:[comp month]+1];
[comp setDay:1];
endOfMonth = [calendar dateFromComponents:comp];
return [endOfMonth dateByAddingTimeInterval:-(60*60*24)];
}
@EskiMag
EskiMag / gist:800041
Created Jan 28, 2011
Meter to degrees based on Geographical Latitude
View gist:800041
// Calculates the degree value of 1 meter at given geographical latitude
#define EARTH_RADIUS 6371000
- (double)meterToDegreeAtLatitude:(double)aLatitudeInDegrees {
double aLatitudeInRadians = aLatitudeInDegrees * (M_PI / 180);
return (1 / (cos(aLatitudeInRadians) * EARTH_RADIUS)) * (180 / M_PI);
}
@EskiMag
EskiMag / gist:627863
Created Oct 15, 2010
Show git branch name in bash prompt
View gist:627863
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
function proml {
local WHITE="\[\033[40;1;37m\]"
local LIGHT_GRAY="\[\033[47;1;30m\]"
case $TERM in
xterm*)
TITLEBAR='\[\033]0;\u@\h:\w\007\]'
You can’t perform that action at this time.