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 / index.html
Last active August 29, 2015 14:08
Dynamic shared assets depending on environment
<script>
document.write(
'<script src="' + env.ASSETS_HOST + '/javascripts/shared/shared.js">\x3C/script>'
);
document.write(
'<link rel="stylesheet" href="' + env.ASSETS_HOST + '/stylesheets/shared.css" />'
);
</script>
@KamilLelonek
KamilLelonek / next_free_port.rb
Created November 8, 2014 07:40
Find next available port on your machine
TCPServer.new('127.0.0.1', 0).addr[1]
@KamilLelonek
KamilLelonek / partials.js
Created November 16, 2014 20:17
Angular-compiled partials from HTML templates
angular.module('partials', [])
.run(['$templateCache', function($templateCache) {
return $templateCache.put('/partials/content.html', [
'',
'<div class="main-content">',
' <div ui-view="Main"></div>',
' <div class="push"></div><span ng-include="\'/partials/footer.html\'"></span>',
'</div>',''].join("\n"));
}])
.run(['$templateCache', function($templateCache) {
@KamilLelonek
KamilLelonek / module.coffee
Created November 16, 2014 20:26
Fetching Angular templates and compiling them into cache
app.run ['$http', '$injector', 'SecurityConstants', ($http, $injector, SecurityConstants) ->
$http.get("#{SecurityConstants.assetsHost}/templates/partials.html").then((response) ->
$injector.get('$compile') response.data
response
)
]
@KamilLelonek
KamilLelonek / extensions_partials_loader.coffee
Last active August 29, 2015 14:09
Resolving external partials by UI-router
angular.module('StudentHunter.ExtensionsModule').factory 'AssetsPartialsLoader',
['$http', '$injector', 'SecurityConstants', ($http, $injector, SecurityConstants) ->
load: ->
$http.get("#{SecurityConstants.assetsHost}/templates/partials.html").then (response) ->
$injector.get('$compile') response.data
response
]
@KamilLelonek
KamilLelonek / routes.coffee
Created November 19, 2014 07:19
UI-router paths
$stateProvider
.state 'anonymous',
abstract: true
resolve:
assetsPartials: ['AssetsPartialsLoader', (AssetsPartialsLoader) ->
AssetsPartialsLoader.load()
]
@KamilLelonek
KamilLelonek / extensions.spec.coffee
Created November 19, 2014 07:30
Testing ExtensionsModule
describe 'ExtensionsModule', ->
beforeEach module 'StudentHunter.Constants'
beforeEach module 'StudentHunter.ExtensionsModule'
beforeEach module 'StudentHunter.SecurityModule'
beforeEach module 'ui.router'
describe '$templateCache decorator', ->
beforeEach module ($provide) ->
$provide.decorator '$compile', ($delegate) ->
return jasmine.createSpy $delegate
@KamilLelonek
KamilLelonek / templates_partials.html
Created November 19, 2014 08:06
Shared templates HTML generated file
<body class="templates templates_partials">
<script id="templates/shared/translate/lang_switch.html" type="text/ng-template">
<ul class="lang-switch" ng-controller="TranslateCtrl as translate">
<li class="lang-switch__lang lang-switch__lang--en">
<button class="lang-switch__btn" ng-class="{'lang-switch__lang--current': translate.isCurrentLang('en')}" ng-click="translate.changeLang('en')" type="button"></button>
</li>
<li class="lang-switch__lang lang-switch__lang--pl">
<button class="lang-switch__btn" ng-class="{'lang-switch__lang--current': translate.isCurrentLang('pl')}" ng-click="translate.changeLang('pl')" type="button"></button>
</li>
</ul>
@KamilLelonek
KamilLelonek / extensions-partials-loader.spec.coffee
Last active August 29, 2015 14:09
Test suite for AssetsPartialsLoader extension
describe 'ExtensionsModule', ->
beforeEach module 'StudentHunter.Constants'
beforeEach module 'StudentHunter.SecurityModule'
beforeEach module 'StudentHunter.ExtensionsModule'
describe "AssetsPartialsLoader load", ->
beforeEach module ($provide) ->
$provide.decorator '$compile', ($delegate) ->
return jasmine.createSpy $delegate
@KamilLelonek
KamilLelonek / ruby_hash_1.rb
Last active August 29, 2015 14:10
Ruby hash quirks - part 1
[1] (pry) main: 0> my_hash = Hash.new []
=> {}
[2] (pry) main: 0> my_hash[:hobbies] << 'dancing';
[3] (pry) main: 0> my_hash[:hobbies] << 'swimming';
[4] (pry) main: 0> my_hash[:skills] << 'java';
[5] (pry) main: 0> my_hash[:skills] << 'php';
[6] (pry) main: 0> my_hash[:skills]
=> ["dancing", "swimming", "java", "php"]
[7] (pry) main: 0> my_hash[:some_random_key]
=> ["dancing", "swimming", "java", "php"]