Skip to content

Instantly share code, notes, and snippets.

View ptcampbell's full-sized avatar
🌲
(◍•﹏•)

Patrick Campbell ptcampbell

🌲
(◍•﹏•)
View GitHub Profile
@carolineschnapp
carolineschnapp / related-products.liquid
Last active December 22, 2022 21:29
Related Products — to add to product.liquid
@cpjolicoeur
cpjolicoeur / gist:3590737
Created September 1, 2012 23:15
Ordering a query result set by an arbitrary list in PostgreSQL

I'm hunting for the best solution on how to handle keeping large sets of DB records "sorted" in a performant manner.

Problem Description

Most of us have work on projects at some point where we have needed to have ordered lists of objects. Whether it be a to-do list sorted by priority, or a list of documents that a user can sort in whatever order they want.

A traditional approach for this on a Rails project is to use something like the acts_as_list gem, or something similar. These systems typically add some sort of "postion" or "sort order" column to each record, which is then used when querying out the records in a traditional order by position SQL query.

This approach seems to work fine for smaller datasets, but can be hard to manage on large data sets with hundreds (or thousands) of records needing to be sorted. Changing the sort position of even a single object will require updating every single record in the database that is in the same sort group. This requires potentially thousands of wri

@rec
rec / airtime-ubuntu.md
Last active July 15, 2017 15:18
Installing SourceFabric's Airtime on a clean Ubuntu server running Virtualmin.

Installing SourceFabric's Airtime on a clean Ubuntu server running Virtualmin.

I'm documenting my experience installing SourceFabric's open source radio station manager Airtime on a clean server Ubuntu 12.04 LTS (Precise Pangolin) server running the popular Virtualmin open-source domain manager.

Virtualmin is sufficiently generic that I imagine the results will be useful to anyone trying to install Airtime on Ubuntu 12.04.

Before you start.

@zakhardage
zakhardage / Much much simpler option selector for Shopify
Last active July 8, 2022 09:50
Much simpler version of Shopify's option_selection.js for separating product options into their own dropdown menus.
<form action="/cart/add" method="post">
{% if product.variants.size > 1 %}
{% if product.options[0] %}
{% assign used = '' %}
<label for="select-one">{{ product.options[0] }}</label>
<select id='select-one' onchange="letsDoThis()">
{% for variant in product.variants %}
{% unless used contains variant.option1 %}
<option value="{{ variant.option1 }}">{{ variant.option1 }}</option>
{% capture used %}{{ used }} {{ variant.option1 }}{% endcapture %}
@vitorbritto
vitorbritto / rm_mysql.md
Last active June 9, 2024 11:06
Remove MySQL completely from Mac OSX

Remove MySQL completely

  1. Open the Terminal

  2. Use mysqldump to backup your databases

  3. Check for MySQL processes with: ps -ax | grep mysql

  4. Stop and kill any MySQL processes

  5. Analyze MySQL on HomeBrew:

    brew remove mysql
    
@kjbrum
kjbrum / search_for_value.php
Last active March 20, 2021 06:24
Check if a value exists in an array/object.
<?php
/**
* Check if an array is a multidimensional array.
*
* @param array $arr The array to check
* @return boolean Whether the the array is a multidimensional array or not
*/
function is_multi_array( $x ) {
if( count( array_filter( $x,'is_array' ) ) > 0 ) return true;
return false;
@juhaelee
juhaelee / react-typescript.md
Last active May 28, 2024 17:41
React + Typescript Cheatsheet

React + Typescript Cheatsheet

Setup

If you use atom... download & install the following packages:

What are Typescript type definition files? (*.d.ts)

@tmslnz
tmslnz / gulpfile.js
Last active October 26, 2021 02:30
Complete example gulpfile.js for https://github.com/tmslnz/gulp-shopify-theme
/*
Streamlined Shopify theme development.
NOTE: depends on module gulp-shopify-theme
npm install --save-dev yargs gulp gulp-sass gulp-changed gulp-sourcemaps gulp-autoprefixer gulp-uglify gulp-concat gulp-replace gulp-plumber gulp-babel browser-sync gulp-if del gulp-add-src gulp-rename gulp-yaml gulp-shopify-theme
Highlights:
- https proxying via BrowserSync
@nrollr
nrollr / MySQL_macOS_Sierra.md
Last active June 7, 2024 20:53
Install MySQL on Sierra using Homebrew

Install MySQL on macOS Sierra

This procedure explains how to install MySQL using Homebrew on macOS Sierra 10.12

Install Homebrew

  • Installing Homebrew is effortless, open Terminal and enter :
    $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • Note: Homebrew will download and install Command Line Tools for Xcode 8.0 as part of the installation process.

Install MySQL

At this time of writing, Homebrew has MySQL version 5.7.15 as default formulae in its main repository :

/* global localStorage */
import {observable, autorunAsync} from 'mobx'
import _ from 'lodash'
function storedObservable (key, defaultValue, debounce) {
let fromStorage = localStorage.getItem(key)
const defaultClone = _.cloneDeep(defaultValue) // we don't want to modify the given object, because userscript might want to use the original object to reset the state back to default values some time later
if (fromStorage) {
_.merge(defaultClone, JSON.parse(fromStorage))
}