Skip to content

Instantly share code, notes, and snippets.

View lucdkny's full-sized avatar

Luke Tran lucdkny

  • Solis Lab
  • Ha Noi, VN
View GitHub Profile
/* Sample JavaScript file added with ScriptTag resource.
This sample file is meant to teach best practices.
Your app will load jQuery if it's not defined.
Your app will load jQuery if jQuery is defined but is too old, e.g. < 1.7.
Your app does not change the definition of $ or jQuery outside the app.
Example: if a Shopify theme uses jQuery 1.4.2, both of these statements run in the console will still return '1.4.2'
once the app is installed, even if the app uses jQuery 1.9.1:
jQuery.fn.jquery => "1.4.2"
$.fn.jquery -> "1.4.2"
*/
@lucdkny
lucdkny / javascript-query-string.js
Created August 28, 2016 08:20 — forked from DavidWells/javascript-query-string.js
JavaScript :: Regex trick: Parse a query string into an object
// http://stevenbenner.com/2010/03/javascript-regex-trick-parse-a-query-string-into-an-object/
// JavaScript regex trick: Parse a query string into an object
var queryString = {};
anchor.href.replace(
new RegExp("([^?=&]+)(=([^&]*))?", "g"),
function($0, $1, $2, $3) { queryString[$1] = $3; }
);
// Usage
@lucdkny
lucdkny / shopify-authentification-flow.md
Created September 12, 2016 19:49 — forked from lbdremy/shopify-authentification-flow.md
Shopify authentification flow

Shopify authentification flow

Request URL:http://www.retailtower.com/app/settings/shopify.php?shop=retailer-lambda.myshopify.com&signature=1fa9c810fec17eea99b04ef21204c91b&timestamp=1370278389
Request Method:GET
Status Code:302 Moved Temporarily

Request Headers

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
@lucdkny
lucdkny / php-regex-meta-description.php
Created October 5, 2016 02:59
How to PHP regex match an HTML document's meta description
<?php
function parseDescription($html) {
// Get the 'content' attribute value in a <meta name="description" ... />
$matches = array();
// Search for <meta name="description" content="Buy my stuff" />
preg_match('/<meta.*?name=("|\')description("|\').*?content=("|\')(.*?)("|\')/i', $html, $matches);
if (count($matches) > 4) {
return trim($matches[4]);
}
@lucdkny
lucdkny / index.md
Created September 30, 2017 20:47 — forked from rstacruz/index.md
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

@lucdkny
lucdkny / Shopify-Checkout-Hack.js
Created March 1, 2018 17:49 — forked from cvieth/Shopify-Checkout-Hack.js
Shopify Checkout Hack - This scipt helps to modify the Shopify Checkout Pages
/**
* Shopify Checkout Hack
*
* This scipt helps to modify the Shopify Checkout Pages. To run this script, add your
* code for each checkout step, compress your code with a tool of your choice and paste
* it to:
*
* Admin > General > Google Analytics > Additional Google Analytics Javascript
*
* @author Christoph Vieth <christoph@vieth.me>
@lucdkny
lucdkny / sticky.js
Created October 30, 2018 07:24 — forked from javierarques/sticky.js
Sticky Sideabr With Vanilla Javascript. Detects scroll and set fixed the element. Live example: http://codepen.io/javiarques/pen/vKdgjR
// Sticky Nav Component
var Sticky = (function() {
'use strict';
var CSS_CLASS_ACTIVE = 'is-fixed';
var Sticky = {
element: null,
position: 0,
addEvents: function() {
@lucdkny
lucdkny / README.md
Created October 31, 2018 16:28 — forked from joyrexus/README.md
Vanilla JS equivalents of jQuery methods

Sans jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
# Insomnia Configuration
## Run the test query
{
shop {
id
name
}
}
# Query Structure Examples
@lucdkny
lucdkny / config.ru
Created May 3, 2019 17:10 — forked from nathany/config.ru
Magical Unicorn Configuration for Heroku
# add something like this to config.ru
# see https://github.com/kzk/unicorn-worker-killer
if Integer(ENV['UNICORN_KILLER'] || 0) != 0
require 'unicorn/worker_killer'
# Max memory size (RSS) per worker
use Unicorn::WorkerKiller::Oom, (350*(1024**2)), (400*(1024**2)), 30, true
end