Skip to content

Instantly share code, notes, and snippets.

View KamilLelonek's full-sized avatar
🏋️‍♂️
Do you even lift?

Kamil Lelonek KamilLelonek

🏋️‍♂️
Do you even lift?
View GitHub Profile
@KamilLelonek
KamilLelonek / string2bool.m
Created March 1, 2014 09:05
String to BOOL extended function
- (BOOL) string2bool: (NSString*) aString {
NSString *normalizedString = [self normalize: aString];
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern: @"(yes|true|tak|ok|right)"
options: NSRegularExpressionCaseInsensitive
error: NULL];
return [regex firstMatchInString: normalizedString options: 0 range: NSMakeRange(0, normalizedString.length)];
}
// [aString boolValue];
@KamilLelonek
KamilLelonek / hash.rb
Created May 16, 2014 11:13
MessageSerializer
class Hash
def symbolize_keys
inject({}) do |result, (key, value)|
new_key = case key
when String then
key.to_sym
else
key
end
new_value = case value
@KamilLelonek
KamilLelonek / pg_with.sql
Created June 13, 2014 15:08
Example of WITH common table expression in PostreSQL
-- DOCUMENTATION: http://www.postgresql.org/docs/9.3/static/queries-with.html
/*
WITH - defines auxilary stetments for larger query. Also called as 'Common Table Expressions' (CTE).
It can create temporary tables just for one query.
It is a basic CRUD statement atatched to another CRUD query.
*/
-- SYNTAX:
@KamilLelonek
KamilLelonek / deploy.rb
Created July 14, 2014 10:39
Upstart deployment
namespace :deploy do
after :publishing, :restart do
on roles(:app) do
within release_path do
execute :sudo, "cp -f #{release_path}/my_config.conf /etc/init/"
execute :sudo, 'initctl restart my_service'
end
end
end
end
@KamilLelonek
KamilLelonek / osx.sh
Created July 18, 2014 19:54
dot-files
#!/bin/bash
echo "Enable full keyboard access for all controls (e.g. enable Tab in modal dialogs)"
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
echo "Enable subpixel font rendering on non-Apple LCDs"
defaults write NSGlobalDomain AppleFontSmoothing -int 2
echo "Enable the 2D Dock"
defaults write com.apple.dock no-glass -bool true
@KamilLelonek
KamilLelonek / config.coffeeenv
Last active August 29, 2015 14:05
Facebook OpenGraph metadata generator
(env) ->
if env.ENV is 'production'
{
API_ENDPOINT: ''
FACEBOOK_ID: ''
FACEBOOK_NAMESPACE: ''
FACEBOOK_OBJECT: ''
}
else
{
@KamilLelonek
KamilLelonek / config.ru
Created September 5, 2014 22:53
Serving static files from Rack
root = 'public'
use Rack::Static,
urls: Dir["#{root}/*"].map { |file| file.sub(root, '')},
root: root,
index: 'index.html',
header_rules: [[:all, { 'Cache-Control' => 'public, max-age=3600' }]]
run -> env {
[
@KamilLelonek
KamilLelonek / create-cookbook.rb
Last active August 29, 2015 14:07
Cookbook CLI creator
#!/usr/bin/env ruby
require 'optparse'
require 'ostruct'
class CookbookCreator
COMPANY_NAME = 'COMPANY_NAME'
EMAIL = 'email@example.com'
COOKBOOK_NAME = 'COOKBOOK_NAME'
class << self
@KamilLelonek
KamilLelonek / is_prime.scala
Created October 24, 2014 21:23
Scala prime numbers
def isPrime(number: Int) = (2 until number) forall (divider => number % divider != 0)
@KamilLelonek
KamilLelonek / block_middle_click.js
Created October 24, 2014 21:32
Block middle click in browser
document.querySelector("a").addEventListener("mousedown", function(e) {
if (e.which === 2) {
this.style.pointerEvents = "none";
}
});
document.body.addEventListener("mouseup", function(e) {
if (e.which === 2) {
document.querySelector("a").style.pointerEvents = "";
}