Skip to content

Instantly share code, notes, and snippets.

View ivorpad's full-sized avatar
🇪🇸
Working from Spain

Ivor ivorpad

🇪🇸
Working from Spain
View GitHub Profile
<?php
if ( !function_exists( 'get_option_tree') ) {
echo '<h1>OptionTree Is Required for this theme</h1>
Download it here: LINK';
}
?>
@ivorpad
ivorpad / gist:1364275
Created November 14, 2011 16:02
Limit Number Of Words In The WordPress Search Query
<!-- I needed to limit the words in the WordPress search query to display it as a title and a long query broke the whole thing, so this did the trick -->
<?php
$my_search_query = get_search_query();
echo string_limit_words($my_search_query, 3);
?>[...]
if ( !class_exists( 'HijackMe' ) ) {
class HijackMe {
public function hijack_menu($objects) {
/**
* If user isn't logged in, we return the link as normal
*/
if ( !is_user_logged_in() ) {
return $objects;
}
/**
'use strict';
/****************************************
* Chapter 3 Exercises: Functions
*****************************************
#EXERCISE 1: Minimum
The previous chapter introduced the standard function Math.min that returns
its smallest argument. We can do that ourselves now. Write a function min that
@ivorpad
ivorpad / gist:ba0847ee3b60976e4a24
Last active August 29, 2015 14:23
A Playlist for Learning Design
@ivorpad
ivorpad / loop_exercise.rb
Created July 8, 2015 17:29
The Each Method - Bloc.io Full Stack
class ArrayModifier
attr_accessor :array
def initialize(array)
@array = array
end
def exclaim
new_array = []
@ivorpad
ivorpad / add_value.rb
Created July 8, 2015 17:31
Loops: Each With Index - Bloc.io: Full Stack
def add_value_and_index(arr)
arr.each_with_index do |e, i|
arr[i] += i
end
end
a = add_value_and_index([2,1,0])
p a
# → [2, 2, 2]
@ivorpad
ivorpad / title_case.rb
Last active August 29, 2015 14:24
Loops: Title Case - Bloc.io: Full Stack
class Title
attr_reader :str
def initialize(str)
@str = str
end
def fix
@ivorpad
ivorpad / setting_attr.rb
Created July 9, 2015 00:41
Hashes: Setting Attributes - Bloc.io: Full Stack
class User
attr_accessor :name, :email, :bio, :age, :sex
def initialize(config = {})
@name = config[:name] || "n/a"
@email = config[:email] || "n/a"
@bio = config[:bio] || "n/a"
@age = config[:age] || "n/a"
@sex = config[:sex] || "n/a"
end
@ivorpad
ivorpad / hash_to_array.rb
Last active August 29, 2015 14:24
Hash To Array: Bloc.io
def hash_to_array(hash = {})
ary = []
hash.each do |k, v|
ary << "#{k} is #{v}"
end
ary
end
hash_to_array({name: "Ivor"})