Skip to content

Instantly share code, notes, and snippets.

@iladarsda
iladarsda / demo.html
Last active April 18, 2019 20:05
Create a custom $parser and add it to the ngModel controller, which in more human translation could mean for example, adding a custom validator to the ng-model of the input.
<!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
<meta charset="UTF-8">
<title>$parsers demo</title>
</head>
<body>
<form name="sampleForm">
<input name="strongSecret" type="text" ng-model="strongSecret" strong-secret required>
<dir ng-messages="sampleForm.strongSecret.$error">
@iladarsda
iladarsda / karma.conf.js
Last active August 29, 2015 14:09
AngularJS/TDD: Sample Karma config file
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
// lib
'./app/lib/angular/angular.js',
'./app/lib/**/angular-*.js',
@iladarsda
iladarsda / batarang.js
Last active August 29, 2015 14:02
Invoke $scope function from the browser console
angular.element($0).scope().someFunction();
@iladarsda
iladarsda / javascript.js
Created May 10, 2014 19:13
jQuery/javascript running functions synchronously
function fun1() {
setTimeout(function() {
console.log("fun1 after 5 s..");
}, 5 * 1000);
return this;
};
function fun2() {
setTimeout(function() {
console.log("fun2 after another 15 s..");
@iladarsda
iladarsda / jquery.js
Created March 13, 2014 12:51
JavaScript - method chaining
$.fn.redBorder = function () {
$(this).css("border", "1px solid red");
return this;
// or shorter "return $(this).css("border", "1px solid red");"
};
$.fn.greyBackground = function () {
return $(this).css("background-color", "grey");
@iladarsda
iladarsda / pattern.js
Created February 21, 2014 14:11
jQuery promise pattern
function doStuff(flag) {
var deferred = $.Deferred();
var err = null,
data = null;
if (flag) {
setTimeout(function() {
data = ["2", "2"];
deferred.resolve(err, data);
}, 5 * 1000)
} else {
@iladarsda
iladarsda / first100primeNumbers.js
Last active August 29, 2015 13:56
JavaScript: find prime numbers
var arr = [];
var x = 0;
while(arr.length < 100){
if(isPrime(x)) { arr.push(x); }
x++;
}
console.log(arr);
console.log(arr.length)
@iladarsda
iladarsda / disable_updates.php
Created February 7, 2014 10:46
WordPress: disable updates
// Disable Theme Updates # 3.0+
remove_action( 'load-update-core.php', 'wp_update_themes' );
add_filter( 'pre_site_transient_update_themes', create_function( '$a', "return null;" ) );
wp_clear_scheduled_hook( 'wp_update_themes' );
// Disable Plugin Updates #3.0+
remove_action( 'load-update-core.php', 'wp_update_plugins' );
add_filter( 'pre_site_transient_update_plugins', create_function( '$a', "return null;" ) );
wp_clear_scheduled_hook( 'wp_update_plugins' );
@iladarsda
iladarsda / dash.php
Created February 7, 2014 10:32
Wordpress 3.8 - enable number of dashboard column in dashboard
function dashboard_columns() {
add_screen_option(
'layout_columns',
array(
'max' => 4,
'default' => 1
)
);
}
add_action( 'admin_head-index.php', 'dashboard_columns' );
@iladarsda
iladarsda / wordpress_no_logo.php
Created February 7, 2014 10:27
WordPress login page, disable wordpress logo
// Login Page - No logo
function new_custom_login_logo() {
echo "<style type='text/css'>h1 { display: none !important; } </style>";
}
add_action('login_head', 'new_custom_login_logo');