Skip to content

Instantly share code, notes, and snippets.

View dsignr's full-sized avatar

Neya dsignr

View GitHub Profile
@dsignr
dsignr / Poll.js
Last active September 15, 2016 05:23
Poll for jQuery until it is loaded
// Source: http://stackoverflow.com/a/17914854/381150
// Sometimes you don't have control over a web page and you need to inject some scripts which are dependent on jQuery.
// However, this will throw a jQuery/$ undefined error and so the only solution is to poll until it's available.
function defer(method) {
if (window.jQuery)
method();
else
setTimeout(function() { defer(method) }, 50);
}
@dsignr
dsignr / simple_split_test.js
Created January 13, 2017 02:58
Simple split test
var siteEvent;
var siteSplit;
jQuery(function() {
siteEvent = function(c, a, l, v) {
dataLayer.push({
'event': 'siteEvent',
'siteEventCategory': c,
'siteEventAction': a,
'siteEventLabel': l,
'siteEventValue': v
@dsignr
dsignr / recover_source_code.md
Created March 12, 2017 07:28 — forked from simonw/recover_source_code.md
How to recover lost Python source code if it's still resident in-memory

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb

Deploying Elixir and Phoenix applications using Docker and Exrm

Goal

By the end of this quick guide, you will know how to compile a Phoenix app release using Exrm and run it inside a Docker container. I've found only a couple of articles that discuss getting an Elixir app up and running inside a Docker container, and even those only touched on some parts of the process. The idea is that this guide will give you a full end-to-end example of how to get all the pieces and parts working together so that you are able to deploy your Phoenix application inside a Docker container.

Assumptions

  1. You already have a working Elixir environment with the Phoenix Framework installed
  2. You have at least basic working knowledge of Docker, and have installed the Docker tools onto your local environment
@dsignr
dsignr / The Technical Interview Cheat Sheet.md
Last active June 1, 2017 18:11 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
  • They are one of the oldest, most commonly used data structures.

Taken from: https://github.com/mperham/sidekiq/wiki/Build-vs-Buy

Open Source software is great, why should you pay money for Sidekiq Pro or Enterprise when you can build it yourself?

Pricing

A senior developer is typically $10,000/mo or more. The price of Sidekiq Pro is roughly $80/mo and Sidekiq Enterprise is roughly $160/mo. Is your business building infrastructure or user functionality? How many days or weeks will it take your team to piece together similar functionality? How long will they spend fixing bugs in production? Paying money for good infrastructure means you have more time to focus on user-facing features.

Baremetrics has a Build vs Buy calculator. Here's some extremely optimistic projections, now let the numbers speak for themselves:

@dsignr
dsignr / IpnController.ex
Created October 22, 2017 09:34 — forked from dereckmartin/IpnController.ex
Phoenix Framework: PayPal IPN Handshake
defmodule AppName.IpnController do
@moduledoc """
IPN Controller.
"""
use AppName.Web, :controller
def create(conn, params) do
# PayPal requires the params returned in the exact order given.
# The map needs to be a list. encode/1 keep the order of a list,
@dsignr
dsignr / pictures.markdown
Created November 24, 2017 09:23 — forked from sent-hil/pictures.markdown
River (getriver.com): Keep a programming journal.

One of my favorite past times is to look at the notebooks of famous scientists. Da Vinci's notebook is well known, but there plenty others. Worshipping Da Vinci like no other, I bought a Think/Create/Record journal, used it mostly to keep jot down random thoughts and take notes. This was great in the beginning, but the conformity of lines drove me nuts. Only moleskines made blank notebooks, so I had to buy one.

At the same time I started a freelance project. The project itself is irrelevant, but suffice to say it was very complex and spanned several months. It seemed like a perfect opportunity to use the moleskine. Looking back, all my entries fell under few categories:

  • Todo
  • Question
  • Thought
  • Bug
  • Feature
@dsignr
dsignr / background.js
Created January 26, 2018 17:38 — forked from danharper/background.js
Bare minimum Chrome extension to inject a JS file into the given page when you click on the browser action icon. The script then inserts a new div into the DOM.
// this is the background code...
// listen for our browerAction to be clicked
chrome.browserAction.onClicked.addListener(function (tab) {
// for the current tab, inject the "inject.js" file & execute it
chrome.tabs.executeScript(tab.ib, {
file: 'inject.js'
});
});
<?php
if ( $_product->is_sold_individually() ) {
$product_quantity = sprintf( '1 <input type="hidden" name="cart[%s][qty]" value="1" />', $cart_item_key );
} else {
$product_quantity = woocommerce_quantity_input( array(
'input_name' => "cart[{$cart_item_key}][qty]",
'input_value' => $cart_item['quantity'],
'max_value' => $_product->get_max_purchase_quantity(),
'min_value' => '0',
'product_name' => $_product->get_name(),