Skip to content

Instantly share code, notes, and snippets.

@roine
roine / shortcuts.md
Last active July 31, 2017 05:25
My favorite PHPStorm, WebStorm shortcuts on MAC
  • command + option + J, context: html, result: suround with template
  • command + shift + return, context: statement or var declaration, result: add semi colon
  • command + return, context: in fragment context, result: run the fragment, convenient when your database is configured to work with the IDE, command + return will execute the sql query
@roine
roine / controllerSpec.js
Last active May 18, 2016 10:49
Some notes on testing AngularJs with Jasmine and Karma.
describe('controllerCtrl', function () {
var $controller,
$rootScope,
$scope;
beforeEach(module('controller'));
beforeEach(inject(function ($injector) {
$controller = $injector.get('$controller');
$rootScope = $injector.get('$rootScope');
@roine
roine / test.js
Last active August 29, 2015 13:56
Quick demo on testing angular provider
describe('Forms module', function () {
var services;
beforeEach(module('app', function(getHtmlProvider){
// set service as the provider to be able to access the setters
services = getHtmlProvider;
}));
// can still test the service by injecting it
@roine
roine / warn.js
Last active December 26, 2015 07:09
warn the user before to unload the page (closing) and if user agree to stay redirect him
var warn = true;
window.onbeforeunload = function(e){
e = e || window.event;
if(warn){
e.returnMessage = 'yop';
setTimeout(function(){
warn = false;
location.href='http://google.fr';
}, 1);
return 'Are you sure? I got a secret to show you before!';

How can I pass parameters from the command-line?

Whenever you're using alias tasks, you can't pass a flag to aliased tasks. Here are a few patterns to deal with that.

For a global setting available to all tasks, use options:

grunt.registerTask('upload', 'Upload code to deploy', function(n) {
  var target = grunt.option('target');
  // use target var to do something useful
});
@roine
roine / shortcuts
Last active December 25, 2015 18:19
Useful shortcuts in ST2
- CTRL+D, **Select a word and all its occurrence**
- CTRL+SHIFT+D, **Copy paste the current line**
- CTRL+M, **Move the caret to the closest bracket or curly bracket**
- CTRL+SHIFT+M, **Select content into the the closest bracket or curly bracket**
- CTRL+L, **Select the current line**
- CTRL+SHIFT+L, **add a caret at the end of each line selected**
- CTRL+K+K, **Delete all the content on the right of the caret**
- CTRL+SHIFT+K, **Delete the current line**
- CTRL+W, **close the current tab**
- CTRL+SHIFT+G, **Wrap content with a tag, can use zen coding**
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
</body>
</html>
@roine
roine / query.sql
Created August 6, 2013 06:47
wp replace localhost by live domain
UPDATE `wp_posts` SET `guid` = REPLACE( `guid` , 'localhost', 'liveserver' )
@roine
roine / header.php
Last active December 20, 2015 09:58
prerender and prefetch in wp
<?php if(is_front_page()): ?>
// do not use prefecth on homepage
<?php elseif (is_singular()): ?>
// load the next post, view http://ideasandpixels.com/get-only-url-of-next-and-previous-posts-wordpress
<link rel="prefetch" href="<?php echo get_permalink(get_adjacent_post(false,'',true)); ?>">
<link rel="prerender" href="<?php echo get_permalink(get_adjacent_post(false,'',true)); ?>">
<?php else: ?>
<link rel="prefetch" href="<?php echo home_url(); ?>">
<link rel="prerender" href="<?php echo home_url(); ?>">
<?php endif; ?>
@roine
roine / config.js
Created July 23, 2013 07:46
meteor accounts config
Accounts.loginServiceConfiguration.remove({service: "github"});
Accounts.loginServiceConfiguration.remove({service: "facebook"});
Accounts.loginServiceConfiguration.remove({service: "twitter"});
Accounts.loginServiceConfiguration.remove({service: "linkedin"});
Accounts.loginServiceConfiguration.insert({
service: "github",
clientId: "ID",
secret: "SECRET"
});