Skip to content

Instantly share code, notes, and snippets.

View kylefox's full-sized avatar
🥊
programming

Kyle Fox kylefox

🥊
programming
View GitHub Profile

A proposal for a framework-agnostic way of building Javascript configuration objects based on different environments.

This proposal focuses on the conventions that will allow for the creation of a plain old JavaScript object. For example:

var environment = new Environment("development");
environment.name; // "development"
environment.config.API_ROOT; // "http://localhost:3000/"
@kylefox
kylefox / gulpfile.js
Created January 15, 2016 17:28
I moved bower dependencies in my Ionic app from `./www/lib` to `./bower_modules` in order to slim down the resulting "www" package. Here are the gulp settings/tasks I use to compile/concatenate everything into `./www/js/libs.js`
var paths = {
// Manually specify the bower resources we actually need.
// This way our index simply has: <script src="js/libs.js"></script>
bower: {
scripts: [
"./bower_modules/ionic/js/ionic.bundle.js",
"./bower_modules/angular-resource/angular-resource.js",
],
fonts: [
"./bower_modules/ionic/fonts/**.*",
def validate(self, data):
if data['new_password1'] != data['new_password2']:
raise serializers.ValidationError({
'new_password2': 'Password confirmation does not match.'
})
# Bayes filter for FotoJournal
if blog.title.contains('photography'):
blog.status = 'Active'
elif blog.title.contains('penis'):
blog.status = 'Spam'
else:
blog.status = 'Unknown'
<a href="/foo.html" data-modal="#foo-modal">Foo</a>
<div id="foo-modal" class="modal">
Hello!
</div>
<script>
$(function() {
$('a[data-modal]').on('click', function() {
$($(this).data('modal')).modal();
@kylefox
kylefox / modal-timed-close.js
Created April 16, 2014 17:56
Close jquery-modal 5 seconds after being opened.
// Attach an event handler to when the modal is opened.
$(document).on($.modal.OPEN, function(event, modal) {
// Use setTimeout to close the modal in 5 seconds (5000 milliseconds).
setTimeout(function() {
$.modal.close();
}, 5000);
});
@kylefox
kylefox / 3-completed-orders.html
Last active December 16, 2015 03:09
How to integrate Granify onto any website using the JavaScript API. (3 of 3)
<!--
Insert this snippet on the page shown to users after an order has been completed.
Place this code immediately before the closing </body> tag to ensure it's run last.
-->
<script type="text/javascript">
Granify.trackOrder({
"created_at": "2013-01-30 14:31:54",
"currency": "USD",
"total_line_items_price": 150.00,
"total_discounts": 25.00,
@kylefox
kylefox / granify-core.html
Last active December 16, 2015 03:09
How to integrate Granify onto any website using the JavaScript API. View http://help.granify.com/install/javascript/ for more information.
<script type="text/javascript">
// ** Replace with your actual Granify Site ID **
var GRANIFY_SITE_ID = 0;
(function(e,t,n){var r,i,s,o,u;u=false;try{o=new RegExp("(?:^|\\W)_gr_test_url=([^;]*)");s=document.cookie.match(o);if(s){if(s[1]==="1")u=true}else{r=Math.random();if(Math.random>.95)u=true;i=new Date(+(new Date)+1e3*60*60*24*2);document.cookie="_gr_test_url="+ +u+";expires="+i.toGMTString()+";path=/"}}catch(a){}if(u)e.replace("javascript.js","javascript.next.js");e=e+"?id="+t;window.Granify=n;n._stack=[];n.init=function(e,t,r){function i(e,t){e[t]=function(){Granify._stack.push([t].concat(Array.prototype.slice.call(arguments,0)))}}var s=n;h=["on","identify","addTag","trackPageView","trackCart","trackOrder"];for(a=0;a<h.length;a++)i(s,h[a])};n.init();var f,l,c,p=document.createElement("iframe");p.src="javascript:false";p.title="";p.role="presentation";(p.frameElement||p).style.cssText="width: 0 !important; height: 0 !important; border: 0 !important; overflow: hidden !important; position: absolute !impor
@kylefox
kylefox / track-cart.html
Last active December 16, 2015 03:08
How to integrate Granify onto any website using the JavaScript API. (1 of 3)
<script type="text/javascript">
Granify.trackCart({
items: [
{
id: "1",
quantity: 1,
price: 100.00,
title: "My Product Title"
},
{
<script type="text/javascript">
// Cart data, such as token, user, and item details. (ex: @cart.to_json)
var params = {
item_count: 3,
total_price: 150,
cart_token: "57b4b4a28e16316cdd028bf6e23ae100"
};
// Additional parameters if this order is "completed".