Skip to content

Instantly share code, notes, and snippets.

View karimmtarek's full-sized avatar

Karim Tarek karimmtarek

View GitHub Profile
// JavaScript
let hidePage = () => {
let payload = {
object_type: 'page',
object_id: 123,
namespace: 'seo',
key: 'hidden',
value: 1,
value_type: 'number_integer'
};
@karimmtarek
karimmtarek / shopify_app.js
Created February 3, 2021 12:43
Shopify app JS SSR Turbolinks setup
// app/javascript/shopify_app/shopify_app.js
import { getSessionToken } from "@shopify/app-bridge-utils";
import $ from "jquery";
const SESSION_TOKEN_REFRESH_INTERVAL = 2000; // Request a new token every 2s
async function retrieveToken(app) {
window.sessionToken = await getSessionToken(app);
}
@karimmtarek
karimmtarek / gist:b66461bf1588e29bc2ce
Last active August 7, 2017 13:40
Montreal Ruby Shops
@karimmtarek
karimmtarek / Cuba Setup.md
Created March 16, 2017 18:02 — forked from Patru/Cuba Setup.md
Setting up Cuba with Sequel, Fortitude, Capybara and Minitest

Setup for Cuba in a sample app

I recently read up quite some articles on microframworks and I liked the idea to try out Cuba instead of the regular Sinatra for a change. Here is what I ended up with.

First of all my Gemfile:

source "https://rubygems.org"
ruby "2.0.0"
@karimmtarek
karimmtarek / Make a Cuba Template.md
Created March 16, 2017 18:02 — forked from Patru/Make a Cuba Template.md
How I got to my Cuba template

Since I did not want to constantly re-invent the wheel I will write down my choices for putting together my Cuba template.

  1. Choose your favorite version of ruby and install it using rbenv (I happened to use MRI 2.2.3 at this point).
  2. create your template directory and CD into it.
  3. fix your ruby version using rbenv local 2.2.3 or somesuch
  4. create a github repository and follow the instructions for the README.md and the first commit.
  5. get a Gemfile from a running project and edit away the stuff I considered project specific
  6. run bundle install, takes a while, but looks nice, remember to add Gemfile.lock to git too
  7. create routes and config directories, want to put stuff in there
  8. create an initial Cuba route in routes/default.rb
@karimmtarek
karimmtarek / dokku_setup.md
Created May 21, 2016 01:35 — forked from joshteng/dokku_setup.md
Using Dokku to deploy a Rails Application

#Goal Deploy your Rails App super easily with Dokku on Digital Ocean cheap cheap!

##Notes

  • Follow 12 factor design (include the rails_12factor gem)
  • Don't forget your Procfile with the command to start up your application server
  • I prefer using external hosted logging services like Logentries (not in this guide)
  • Set up performance monitoring AppSignal or New Relic (not in this guide)
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Returns the result of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
  • Dynamic Dispatch
  • Dynamic Method
  • Ghost Methods
  • Dynamic Proxies
  • Blank Slate
  • Kernel Method
  • Flattening the Scope (aka Nested Lexical Scopes)
  • Context Probe
  • Class Eval (not really a 'spell' more just a demonstration of its usage)
  • Class Macros
To replace $130 with 130&thinesp;$
Search: \$(\d+)
Replace: \1 $
To strip classes/id/style
Search: \s+class="[^"]*"
Replace:
<% 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>