Skip to content

Instantly share code, notes, and snippets.

View dkhgh's full-sized avatar

dkhgh

  • Defacto
View GitHub Profile
@WalrusSoup
WalrusSoup / LazyLoadIntercom.js
Created October 29, 2021 17:58
Lazy load intercom on scroll to help speed up PageSpeed Insights
// replace YOUR_INTERCOM_URL_HERE with your app_id
var intercomLoader = function() {
(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',w.intercomSettings);}else{var d=document;var i=function(){i.c(arguments);};i.q=[];i.c=function(args){i.q.push(args);};w.Intercom=i;var l=function(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/YOUR_INTERCOM_URL_HERE';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s, x);};if(document.readyState==='complete'){l();}else if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})();
window.Intercom('boot', {
app_id: 'YOUR_INTERCOM_URL_HERE'
})
window.removeEventListener('scroll', intercomLoader);
}
window.addEventListener('scroll', intercomLoader);
@rickyhaswifi
rickyhaswifi / model.rb
Last active December 29, 2022 20:56
Youtube & Spotify Embedded Content for Rails - Place this in model to slice specific strings
#YOUTUBE
def youtube_id
youtube_id = self.modelkey
youtube_id.gsub("https://www.youtube.com/watch?v=", "")
end
#Call as @model.youtube_id
<iframe width="560" height="315" src="https://www.youtube.com/embed/<%= @.youtube_id %>" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
#SPOTIFY
@handofthecode
handofthecode / application.html.erb
Last active March 27, 2022 10:55 — forked from mebezac/application.html.erb
Rails Ajax Flash Messages
<div id="main" role="main">
<div class="container">
<div class="row">
<div class="span12" id="top-div"> <!--! added "top-div" id to help with ajax -->
<%= render 'layouts/messages' %>
<%= yield %>
</div>
</div>
<footer>
</footer>
@xeraa
xeraa / helper.rb
Created August 4, 2015 23:48
Middleman: Fully automated alternate language links
# Returns a hash of localized paths for a given page
def localized_paths_for(page)
localized_paths = {}
(langs).each do |locale|
# Loop over all pages to find the ones using the same templates (proxied_to) for each language
sitemap.resources.select do |resource|
if resource.proxied_to == page.proxied_to && resource.metadata[:options][:lang] == locale
localized_paths[locale] = resource.url
break
@gefangenimnetz
gefangenimnetz / materialDesignShadowHelper.less
Last active December 17, 2022 17:21
Less css box-shadow helper for cards & modals according to Googles Material Design spec.
/**
* A mixin which helps you to add depth to elements according to the Google Material Design spec:
* http://www.google.com/design/spec/layout/layout-principles.html#layout-principles-dimensionality
*
* Please note that the values given in the specification cannot be used as is. To create the same visual experience
* the blur parameter has to be doubled.
*
* Author: Florian Kutschera (@gefangenimnetz), Conceptboard GmbH (@conceptboardapp)
*
* Example usage:
@jurre
jurre / gist:8030430
Last active December 31, 2015 18:59
string to pastel color
def pastel_color_for_string(string)
start_color = 128
total_offset = 64
hex_value = [
0,
string_to_integer_hash(string) % total_offset,
string_to_integer_hash(string.reverse) % total_offset,
total_offset
].sort.each_cons(2).map do |a, b|
"%02x" % (start_color + b - a)
@ls-lukebowerman
ls-lukebowerman / sitemap.xml.erb
Created August 7, 2012 17:59
Sitemap (sitemaps.org) generator for Middleman
<% pages = sitemap.resources.find_all{|p| p.source_file.match(/\.html/) } %>
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<% pages.each do |p| %>
<url>
<loc>http://youdomain.com/<%=p.destination_path.gsub('/index.html','')%></loc>
<priority>0.7</priority>
</url>
<% end %>
</urlset>
@tsabat
tsabat / zsh.md
Last active December 25, 2023 19:16
Getting oh-my-zsh to work in Ubuntu