Skip to content

Instantly share code, notes, and snippets.

@adyngom
adyngom / theme_name_scripts.php
Last active Jul 9, 2016
Properly adding conditional styles ( IE 8 , IE 9 etc...) and scripts to your wordpress theme
View theme_name_scripts.php
<?php
/**
* Wordpress is @ 4.5.3
* https://developer.wordpress.org/reference/functions/wp_style_add_data/
* https://developer.wordpress.org/reference/functions/wp_script_add_data/
* no need to use global $wp_data
* add to your theme's functions.php file
* */
define('THEME_TEMPLATE_PATH', get_template_directory_uri());
@adyngom
adyngom / app.js
Created Jul 27, 2016
Dynamic Search Filtering in Angular JS Example
View app.js
(function () {
'use strict';
angular
.module('va', [])
.filter('highlight', highlight)
.factory('query', query)
.controller('searchlist', searchList);
highlight.$inject = ['$sce'];
function highlight($sce) {
@adyngom
adyngom / fizzbuzz.html
Created Jan 27, 2017
FizzBuzz Challenge
View fizzbuzz.html
<ul id="fizzbuzz">
</ul>
<script type="text/javascript" src="fizzbuzz.js"></script>
View flattened.js
/**
* Write some code, that will flatten an array of arbitrarily nested arrays of integers into a
* flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4].
**/
/**
* forEach solution
**/
const FlatLinerFE = function(arr) {
let flatline = [];
View es6-int-classes-initial-code.js
'use strict';
const Felidea = function() {
const bigCats = ['tiger','lion','jaguar', 'leopard', 'snow leopard'];
const midSize = ['clouded leopard', 'sunda clouded leopard'];
let species = Object.freeze([...bigCats, ...midSize]);
return species;
}
const Panthera = function(kind, name, options) {
// check if the kind belong to the species list
View findMissinNumber.js
var findMissingNumber = function(arr) {
let size = arr.length;
console.log(size);
if(!size) {
return false;
}
// could sort the array first and get
// first and last index
// not sure which one would be faster
//let lower = Math.min.apply(null, arr);
View isPalindrome.js
String.prototype.isPalindrome = function() {
let specialChars = /[`~!@#$%^&*()_|+\-=?;’—:'",.<>\{\}\[\]\\\/]/gi;
let prepped = this.replace(specialChars, '').replace(/\s/g, '').toLowerCase();
return ( prepped === prepped.split('').reverse().join('') )
};
console.log("Matam", "Matam".isPalindrome()); // true
console.log("racecar", "racecar".isPalindrome()); // true
console.log("race car", "race car".isPalindrome()); // true
View binary-gap-solution.js
function solution(N) {
const nope = 0;
if(!N) return nope;
let bin = (N >>> 0).toString(2);
let binLength = bin.length;
View odd-occurences-in-array.js
function solution(A) {
return A.reduce( (a,c) => a ^= c ); // xor operator is sexy :)
}
var barr = [10,10, 4, 3, 4, 6, 8, 8, 6];
console.log(solution(barr)); // returns 3;
View frogJump.js
function solution(X, Y, D) {
// write your code in JavaScript (Node.js 6.4.0)
if( D <= 0 || Y <= X ) return 0;
var J = Math.ceil( ( Y - X) / D );
return J;
}
console.log( solution(10, 85, 30) ); // 3