Skip to content

Instantly share code, notes, and snippets.

Avatar

Štefan Ľupták EskiMag

View GitHub Profile
@EskiMag
EskiMag / benchmark.exs
Created Apr 19, 2020
Benchmarking performance of slicing text in different formats/ways
View benchmark.exs
# 1024 bytes long string
string = """
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis tempus iaculis erat. Cras orci enim, vulputate a elementum at, rutrum pulvinar sem. Donec gravida quam at lectus sagittis, eu facilisis felis scelerisque. Nulla quis leo quis ipsum sollicitudin pharetra. Interdum et malesuada fames ac ante ipsum primis in faucibus. Donec bibendum porttitor hendrerit. In hac habitasse platea dictumst.
Sed blandit massa ut lorem accumsan, ut suscipit erat aliquet. Ut vulputate sit amet ligula non auctor. Nullam pharetra vestibulum velit, lobortis ultrices ante blandit quis. Curabitur gravida fringilla enim non pulvinar. Vestibulum facilisis turpis ipsum, ac tempor magna varius at. Cras pulvinar mi in varius mattis. Curabitur viverra nibh est, eu consectetur magna euismod eget. Suspendisse potenti. Vestibulum hendrerit auctor dui id imperdiet. Quisque congue enim non eros lobortis, rhoncus aliquam lacus eleifend. Nam et malesuada mauris, et semper velit. Aenean volutpat cursus or
@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 keybase.md

Keybase proof

I hereby claim:

  • I am eskimag on github.
  • I am eskimag (https://keybase.io/eskimag) on keybase.
  • I have a public key whose fingerprint is D7DF 3426 8D5A 3781 3F8B 5054 7128 89AF 8B9F 420D

To claim this, I am signing this object:

@EskiMag
EskiMag / swift_instancetype_problem
Created Dec 10, 2014
How to write 'instancetype'-like code in Swift
View swift_instancetype_problem
import Foundation
import UIKit
extension UIViewController {
class func fromMainStoryboard () -> UIViewController {
var storyboardID = NSStringFromClass(self)
let dotRangeOptional = storyboardID.rangeOfString(".", options: NSStringCompareOptions.allZeros)
if let dotRange = dotRangeOptional {
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
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
@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
You can’t perform that action at this time.