Skip to content

Instantly share code, notes, and snippets.

@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 / tips.md
Created June 9, 2014 04:12
Angular tips

#Performance

  1. When using $timeout if $scope does not update set false to the third argument to skip the digest. (see angular doc)
  2. Add strictDi when bootstraping, it should throw an error when a function is not annotated. Annotating is important if you need to minify your code. This feature has been introduced in v1.3.0-beta.6 (see ticket, see performance)
@roine
roine / plugin.php
Last active August 29, 2015 14:07
wp have a checkbox in option page to be user specific saved
add_action( 'admin_init', 'register_modal_email_settings' );
function register_modal_email_settings()
{
if( !get_option( $user->user_nicename . '_plugin_options' ) ){
register_setting( 'section_email_modal', $user->user_nicename . '_plugin_options', '0' );
}
add_settings_section( 'section_foo', 'Foo settings', 'foo_desc', 'foo' );
add_settings_field( 'bar', 'Bar field', 'bar_option', 'foo', 'section_foo' );
}
@roine
roine / matchers.js
Created December 3, 2014 19:27
Jasmine matchers
var matchers = {
toBePromise: function(util){
return {
compare: function(actual){
var result = {}
result.pass = typeof actual === "object" && typeof actual.then === "function";
if(result.pass){
result.message = "Expected var not be a Promise";
}
@roine
roine / forof.js
Created December 5, 2014 02:00
Notes on ES6
var numbers = ['a', 'b', 'c'];
for(let i of numbers){
console.log(i); // a b c
}
var users = [{
firstname: 'jon',
lastname: 'dem'
},
@roine
roine / README.md
Last active August 29, 2015 14:27 — forked from JoelBesada/README.md
Backtick - Angular: count watchers

This is an example command for Backtick. A Backtick command consists of some executable JavaScript and a bit of metadata in JSON.

Here are the required steps to create a command:

  1. Create a new Gist with a command.js and command.json file, or simply fork this one.

  2. Write your JavaScript in command.js. This will be injected into and executed on the page the user is currently on when they run it.

  3. Add some metadata to the command.json file:

  • name: The name of the command.
@roine
roine / command.js
Last active August 29, 2015 14:27
prettify CSS for backtick
(function () {
'use strict';
// cssbeautify
(function(){"use strict";function a(a,b){function s(a){return" "===a||"\n"===a||" "===a||"\r"===a||"\f"===a}function t(a){return"'"===a||'"'===a}function u(a){return h>="a"&&"z">=h||h>="A"&&"Z">=h||h>="0"&&"9">=h||"-_*.:#".indexOf(a)>=0}function v(){var a;for(a=m;a>0;a-=1)g+=c.indent}function w(){g=r(g),p?g+=" {":(g+="\n",v(),g+="{"),"\n"!==i&&(g+="\n"),m+=1}function x(){var a;m-=1,g=r(g),q&&(a=g.charAt(g.length-1),";"!==a&&"{"!==a&&(g+=";")),g+="\n",v(),g+="}",f.push(g),g=""}var c,f,h,i,j,k,l,m,n,o,r,d=0,e=a.length,g="",p=!0,q=!1;for(c=arguments.length>1?b:{},c.indent===void 0&&(c.indent=" "),"string"==typeof c.openbrace&&(p="end-of-line"===c.openbrace),"boolean"==typeof c.autosemicolon&&(q=c.autosemicolon),r=String.prototype.trimRight?function(a){return a.trimRight()}:function(a){return a.replace(/\s+$/,"")},l={Start:0,AtRule:1,Block:2,Selector:3,Ruleset:4,Property:5,Separator:6,Expression:7,URL:8},m=0,k=l.Start,o=!1,f=[],a=a.replace(/\r\n/g,"\n");e>d;)if
@roine
roine / jquery.revealit.js
Created July 4, 2012 07:12
auto add checkbox after input type password, checking it allow to see the content
var reveal = function(msgIn, msgOut){
msgIn = msgIn || "Reveal it!";
msgOut = msgOut || "Hide It!";
$("input[type=password]").each(function(){
var self = $(this);
$(this).after("<span id='revealctrl'></span>")
.next()
.append("<input type=checkbox id='revealCheckbox'>")
@roine
roine / index.html
Created July 6, 2012 05:32
shadow and light
<link href="http://fonts.googleapis.com/css?family=Squada+One" rel="stylesheet" type="text/css">
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<link href="style.css" rel="stylesheet" type="text/css">
<script src="script.js"></script>
<body>
<span id="pos">
</span>
<span id="text">
if(localStorage in window)
if(typeof localStorage.view == 'undefined') localStorage.view = 0
localStorage.view++;
maxView = 10;
if(maxView > localStorage.view){
// display a message 10 times
}