Skip to content

Instantly share code, notes, and snippets.

View zealoushacker's full-sized avatar

Alex Notov zealoushacker

View GitHub Profile
@zealoushacker
zealoushacker / GPG and git on macOS.md
Created March 9, 2017 17:29 — forked from danieleggert/GPG and git on macOS.md
How to set up git to use the GPG Suite

GPG and git on macOS

Setup

No need for homebrew or anything like that. Works with https://www.git-tower.com and the command line.

  1. Install https://gpgtools.org -- I'd suggest to do a customized install and deselect GPGMail.
  2. Create or import a key -- see below for https://keybase.io
  3. Run gpg --list-secret-keys and look for sec, use the key ID for the next step
  4. Configure git to use GPG -- replace the key with the one from gpg --list-secret-keys
@zealoushacker
zealoushacker / process_statements.rb
Last active February 19, 2016 03:59
A quick script to clean up my bank statements from Alamosa State Bank to just extract withdrawals and deposits as CSV
#!/usr/bin/env ruby
require "csv"
dep_or_withd = false
CSV.open("statement.csv", "wb") do |csv|
csv<<["*Date", "*Amount", "Payee", "Description", "Reference", "Check Number"]
IO.foreach("./statement_dump.txt") do |line|
line_date = line.match(/^\d{2}\/\d{2}\/\d{2}/)
@zealoushacker
zealoushacker / update-all-thumbs-for-a-given-other-meta_key-in-woocommerce.sql
Created September 14, 2015 19:36
update-all-thumbs-for-a-given-other-meta_key-in-woocommerce
# in WC/WP
# provided that we want to update all
# thumbnails of all products to a specific thumbnail id (in this case 10759),
# where no thumbnail exists,
# and where a specific other meta_key is matched (in this case 'attribute_pa_finish')
# and where a specific other meta value is matched (in this case 'black-melamine')
# this is the fun little query that will do it
update wp_4_postmeta as m
inner join
(select * from wp_4_postmeta
@zealoushacker
zealoushacker / convert-wordpress-variation-select-to-radios.js
Created September 9, 2015 03:37
This script converts wordpress' default variable product's select to a bunch of swatch options. Style as you need it.
// this is super hacky, but it gets the job done
// this may be placed at the end of your theme's woocommerce/single-product/add-to-cart/variable.php
// or in the appropriate js file that you load via wp_enqueue_scripts
// if you want to be clean about it
(function($) {
var $variationsForm = $('form.variations_form');
$variationsForm.find('select').each(
function(i, select){
var $select = $(select);
$select.find('option').each(function(j, option){
@zealoushacker
zealoushacker / why_iframes_are_good_for_widget_development.md
Last active September 7, 2015 14:35
Why iframes are great for embeddable widget development

Why iframes are good for embeddable widget development

There are generally two ways to build embeddable widgets to be embeddable by an arbitrary widget consuming site, that isn't on the same domain as where the widget is hosted (think stripe checkout, olark chat, or zendesk support widgets as examples):

  1. Render the widget into the embedding site's designated <div> or some other html container element
  2. Render the widget into the embedding site's designated <iframe> element

To be sure, <iframe> is generally a pretty horrible way to go. But, as usual there are tradeoffs, and in one very specific use case, it's pretty great: building embeddable widgets. No, it's not because most other companies of any import that build widgets, with some very smart engineers, use the <iframe> method - I am not one for appeals to authority - and there are some notable exceptions, like olark, though they are probably hating the maintenance of the widget ui and associated css. Primarily, the core reasons why `<ifram

#Four Ways To Do Pub/Sub With jQuery and jQuery UI (in the future)

Between jQuery 1.7 and some of work going into future versions of jQuery UI, there are a ton of hot new ways for you to get your publish/subscribe on. Here are just four of them, three of which are new.

(PS: If you're unfamiliar with pub/sub, read the guide to it that Julian Aubourg and I wrote here http://msdn.microsoft.com/en-us/scriptjunkie/hh201955.aspx)

##Option 1: Using jQuery 1.7's $.Callbacks() feature:

$.Callbacks are a multi-purpose callbacks list object which can be used as a base layer to build new functionality including simple publish/subscribe systems. We haven't yet released the API documentation for this feature just yet, but for more information on it (including lots of examples), see my post on $.Callbacks() here:

@zealoushacker
zealoushacker / person.rb
Created November 5, 2014 23:27
Person object with specs
class Person
attr_reader :first_name, :last_name, :gender
def self.genders
[:male, :female]
end
def initialize first_name, last_name, gender
unless Person.genders.include? gender
raise "Can't birth people, unless they are #{Person.genders}"
@zealoushacker
zealoushacker / secure_your_keys.md
Last active August 29, 2015 14:08
Checklist for securing API keys

Protecting your API keys for nodejs apps

Don't check in your API keys into your git repo, ever.

Checklist:

  1. If you've already checked in an API key for a service to your git repo, generate a new key
  2. Create a file called .env in your project's root directory
  3. Store your API keys in your .env files in this format: API_KEY_NAME=api_key_value
  4. Anywhere you had written your key in your js files, use the expression process.env.API_KEY_NAME to get the value of the API key from your environment
@zealoushacker
zealoushacker / index.js
Created October 29, 2014 17:16
sequelize models/index.js file drop-in replacement
"use strict";
var fs = require("fs");
var path = require("path");
var Sequelize = require("sequelize");
var env = process.env.NODE_ENV || "development";
var config = require(__dirname + '/../config/config.json')[env];
var db = {};
var sequelize;
var match;
Steps to install and run PostgreSQL 9.2 using Homebrew (Mac OS X)
(if you aren't using version 9.1.5, change line 6 with the correct version)
1. launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
2. mv /usr/local/var/postgres /usr/local/var/postgres91
3. brew update
4. brew upgrade postgresql
5. initdb /usr/local/var/postgres -E utf8
6. pg_upgrade -b /usr/local/Cellar/postgresql/9.1.5/bin -B /usr/local/Cellar/postgresql/9.2.0/bin -d /usr/local/var/postgres91 -D /usr/local/var/postgres
7. cp /usr/local/Cellar/postgresql/9.2.0/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/