Skip to content

Instantly share code, notes, and snippets.

View checkthemethod's full-sized avatar
🎯
Focusing

Richard Saethang checkthemethod

🎯
Focusing
View GitHub Profile
@checkthemethod
checkthemethod / adding-favorites-to-rails
Last active February 21, 2019 02:49
Adding Favorites to Rails App
rails g model Favorites posts:references user:references
rake db:migrate
rails g controller Favorites update
@checkthemethod
checkthemethod / jquery-validator-no-space.js
Last active February 21, 2019 02:55
Check for spaces using the jQuery validator
jQuery.validator.addMethod("noSpace", function(value, element) {
return $.trim(value) != "";
}, "No space please and don't leave it empty");
@checkthemethod
checkthemethod / require-checkbox-validation.js
Last active February 21, 2019 02:55
Require Checkbox Validation with jQuery validate
$.validator.addMethod('requireOne', function (value, element) {
return $(element).closest('.form-group').find('input.require-one:checked').size() > 0; }, 'Please check at least one box.');
@checkthemethod
checkthemethod / copyToClipboard.js
Last active May 11, 2018 18:21
Copy to Clipboard using navigator.clipboard
/**
* if browser doesn't have navigator.clipboard, use this to copy the url to clipboard
* @param text
*/
export const fallbackCopyTextToClipboard = (text) => {
let textArea = document.createElement('textarea')
textArea.value = text
document.body.appendChild(textArea)
textArea.focus()
textArea.select()
@checkthemethod
checkthemethod / hardware-accelerated.css
Last active February 21, 2019 02:56
Hardware-Accelerated CSS Tricks
[http://blog.teamtreehouse.com/increase-your-sites-performance-with-hardware-accelerated-css](http://blog.teamtreehouse.com/increase-your-sites-performance-with-hardware-accelerated-css)
.cube {
-webkit-transform: translate3d(250px,250px,250px)
rotate3d(250px,250px,250px,-120deg)
scale3d(0.5, 0.5, 0.5);
}
In some cases, you might not want a 3D transformation on the element, but still take advantage of GPU acceleration. That’s when a few simple CSS properties come in handy that trick the browser into triggering GPU acceleration.
Even though we’re not animating an element in 3D space, we can enable 3D rendering. At the very least, the transform: translateZ(0); declaration triggers GPU acceleration in modern desktop and mobile browsers. This seems to be the most effective way of triggering GPU acceleration (all vendor prefixes included):
@checkthemethod
checkthemethod / JSONreader.js
Last active February 21, 2019 02:57
Read JSON via AJAX with vanilla JS
function ajax_get(url, callback) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
console.log('responseText:' + xmlhttp.responseText);
try {
var data = JSON.parse(xmlhttp.responseText);
} catch(err) {
console.log(err.message + " in " + xmlhttp.responseText);
return;
@checkthemethod
checkthemethod / jekyll-social-share-partial
Last active February 21, 2019 02:59
Sharing partial for social links in Jekyll with Font Awesome icons
<div class="share-page">
<p>Share this:</p>
<a href="https://twitter.com/intent/tweet?text={{ page.title }}&url={{ site.url }}{{ page.url }}&via={{ site.twitter_username }}&related={{ site.twitter_username }}" rel="nofollow" target="_blank" title="Share on Twitter"><i class="fa fa-twitter" aria-hidden="true"></i>
</a>
<a href="https://facebook.com/sharer.php?u={{ site.url }}{{ page.url }}" rel="nofollow" target="_blank" title="Share on Facebook"><i class="fa fa-facebook-official" aria-hidden="true"></i>
</a>
<a href="https://plus.google.com/share?url={{ site.url }}{{ page.url }}" rel="nofollow" target="_blank" title="Share on Google+"><i class="fa fa-google-plus" aria-hidden="true"></i>
</a>
</div>
@checkthemethod
checkthemethod / social-metatags.html
Created October 7, 2015 22:35
Meta tags for fb/twitter on site
<meta property="og:title" content="NAME OF SITE">
<meta property="og:description" content="META DESCRIPTION OF SITE">
<meta property="og:image" content="http://www.EXAMPLE.com/images/EXAMPLE-fb-share.jpg">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@username">
<meta name="twitter:title" content="NAME OF SITE">
<meta name="twitter:description" content="META DESCRIPTION OF SITE">
<meta name="twitter:image" content="http://www.EXAMPLE.com/images/EXAMPLE-fb-share.jpg">