Skip to content

Instantly share code, notes, and snippets.

View electricjesus's full-sized avatar
🐅

Seth Malaki electricjesus

🐅
View GitHub Profile
@electricjesus
electricjesus / nginx.conf
Created May 8, 2014 06:09
NGINX Meteor with Websockets
# we're in the http context here
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# the Meteor / Node.js app server
server {
server_name yourdomain.com;
@electricjesus
electricjesus / cc-verification.js
Created August 13, 2014 09:17
getCreditCardType
// automatic creditcard detection @Seth Malaki `Electric Jesus` (c) 2012
// returns credit type on success. returns null if either unsupported or fails checksum validation (Luhn algorithm).
function getCreditCardType(accountNumber, doVerify)
{
var typeKey = null;
// inspect account number, no dashes
var creditCardInspectors = {
VI : /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/, // Visa
MC : /^5[1-5][0-9]{14}$/, // Mastercard
// Level 1 mission
// The code does not execute properly. Try to figure out why.
function multiply(a, b){
a * b
}
// Level 2 mission
//2. Correct this code, so that the greet function returns the expected value.
@electricjesus
electricjesus / test.php
Created December 17, 2014 06:11
Script to test for server uptime [Magento]
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
header("Content-type: application/json");
require_once "app/Mage.php";
Mage::app($_SERVER['MAGE_RUN_CODE'], $_SERVER['MAGE_RUN_TYPE']);
$resource = Mage::getSingleton('core/resource');
/* Functional Programming 101
1.) Create a function 'last' that has the following use cases:
- last("abc") // --> outputs "c"
- last(1,2,3,"D") // --> outputs "D"
- last([1,2,3,4]) // --> outputs 4
@electricjesus
electricjesus / doubledecode-htmlent.py
Created March 13, 2012 17:13 — forked from litchfield/doubledecode.py
Double decode utf8 and cp1252
#!/usr/bin/env python
"""
modded doubledecode.py
Seth Malaki (seth d-o-t malaki a-t gmail d-o-t com)
mainly this modification aims to replace special characters with html entities instead.
Test status: todo/untested.
@electricjesus
electricjesus / elasticsearch.rake
Created October 31, 2012 04:58 — forked from jarosan/elasticsearch.rake
Elasticsearch reindex task
# Run with: rake environment elasticsearch:reindex
# must have : tire, will_paginate
# added multiple classes to reindex
namespace :elasticsearch do
desc "re-index elasticsearch"
task :reindex => :environment do
[Place, Time] # <--- CONFIGURE HERE: Provided that you have classes called 'Place and Time which have the necessary Tire callbacks
@electricjesus
electricjesus / CMS
Created November 27, 2012 18:12
General purpose Magento block/phtml inclusion call in CMS entries (pages/static blocks)
{{block type="core/template" name="my_product_list" template="custom/product_list.phtml"}}
# for later on when we want to use www schema
#server {
# listen 80;
# server_name DOMAIN.com;
# rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www
#}
server {
listen 80;

This is an example of how to write bdd style tests for brunch.io projects and the required setup