Skip to content

Instantly share code, notes, and snippets.

View rbk's full-sized avatar

Richard Keller rbk

View GitHub Profile
@rbk
rbk / functions.php
Created May 29, 2013 02:28
PHP function that turns vimeo and youtube urls in to videos.
<?php
function filter_video_links( $content ){
// Regular Expressions
$youtube_link = '@^\s*https?://(?:www\.)?(?:youtube.com/watch\?|youtu.be/)([^\s"]+)\s*$@im';
$vimeo_link = '@^\s*https?://(?:www\.)?(?:vimeo.com/)@im';
if( preg_match( $vimeo_link, $content ) ) {
// vimeo
$content = preg_replace( $vimeo_link, 'http://player.vimeo.com/video/', $content );
@rbk
rbk / gist:5750784
Created June 10, 2013 17:47
get events
$events = new WP_Query(
array(
'post_type'=>'guru_events',
'orderby' => 'meta_value',
'meta_key' => 'the_event_date',
'order' => 'ASC'
)
);
while ( $events->have_posts() ) : $events->the_post();
@rbk
rbk / common.js
Last active December 26, 2015 19:19
This is a placeholder workaround for text inputs
jQuery(document).ready(function($){
$('input[type=text]').each(function(){
$(this).val( $(this).attr('placeholder') );
});
$('input[type=text]').keyup(function(){
var placeholder = $(this).attr('placeholder');
var regex = new RegExp(placeholder);
$(this).val( $(this).val().replace(regex, ''))
@rbk
rbk / scraper.rb
Created October 29, 2013 21:39
Url finder from ruby class
# extract urls from a website
require "open-uri"
if ARGV.size > 0
url = ARGV[0]
open(url) do |data|
data.each_line do |line|
if result = line.match(/href="(.*?)"/)
@rbk
rbk / common.js
Last active December 26, 2015 22:29
Creating placeholder for ie8 with plain javascript
var forms = document.forms;
for(var i=0; i< forms.length;i++){
for( var t=0; t <forms[i].elements.length; t++ ){
//console.log( forms[i].elements[t].attributes )
var placeholder = forms[i].elements[t].attributes.placeholder.value;
forms[i].elements[t].attributes.value.value = placeholder;
forms[i].elements[t].addEventListener('focus',function(){
this.value = '';
})
forms[i].elements[t].addEventListener('blur',function(){
@rbk
rbk / functions.php
Created October 30, 2013 16:37
Modify post columns in wordpress
<?php
// modify post columns
add_filter('manage_guru_employees_posts_columns', 'employees_posts_columns', 5);
add_action('manage_guru_employees_posts_custom_column', 'employee_custom_columns', 5, 2);
function employees_posts_columns($columns){
unset( $columns['riv_post_thumbs'] );
unset( $columns['date'] );
$columns['phone_number'] = __('Phone');
@rbk
rbk / distance.rb
Created November 13, 2013 05:22
test
# distance class
class Distance
attr_accessor :value, :unit
@@var # class variable
@var # object variable
# @km = "miles / 0.62136"
# @miles = "km * 0.6214"
@rbk
rbk / gist:7904050
Created December 11, 2013 02:08
Tut test code
Tut.to_tut( "Wow! Look at this get converted to Tut!" ) { |c| puts c }
# should outout : Wutowut! Lutookut atut tuthutisut gutetut cutonutvuteruttutedut tuto Tututut!
tut_string = ""
Tut.to_tut( "I'm in tut but I want to be in english." ) { |c| tut_string += c }
puts tut_string
# should output : I'mut inut tututut bututut I wutanuttut tuto bute inut enutgutlutisuthut.
Tut.to_english( tut_string ) { |c| print c }
# should output : I'm in tut but I want to be in english.
require_relative 'class_tut_file'
require 'test/unit'
class TestTut < Test::Unit::TestCase
def setup
@tut = "I'mut inut tututut bututut I wutanuttut tuto bute inut enutgutlutisuthut."
@english = "I'm in tut but I want to be in english."
end
def test_is_tut
assert_equal true, Tut.is_tut?( @tut )
@rbk
rbk / scroller-resizer
Created September 25, 2014 21:27
Ugly jquery
$(document).ready(function(){
$(window).bind("scroll",function(e){
if($(document).width() > 551) {
if($(document).height() > 1000) {
if($(document).scrollTop() > 100) {
$( ".site-branding" ).addClass( "site-branding-response" );
$( ".site-title" ).addClass( "site-title-response" );
$( ".menu-item" ).addClass( "menu-item-response" );
$( ".company_contact_info" ).addClass( "company_contact_info_response" );
} else {