Skip to content

Instantly share code, notes, and snippets.

View radius's full-sized avatar

darius daftary radius

View GitHub Profile
@radius
radius / gist:9102288
Created February 19, 2014 21:42
AngularJS module for executing an expression when an element is shown
angular.module('OnShow', []).
directive('onShow', function () {
return {
controller: function($scope) {
$scope.fireOnce = false;
this.setFireOnce = function(bool) {
$scope.fireOnce = bool;
}
},
link: function(scope, elm, attr) {
@radius
radius / Logger.js
Created February 10, 2012 02:08
Little JS logger class
var Logger = (function() {
return {
active: true,
post: false,
log: function(obj, type) {
if(Logger.active) {
console.log(obj);
}
if(Logger.post) {
$.post(Logger.post, {
@radius
radius / inputPlaceholder.jquery.js
Created May 16, 2012 15:30
Input Placeholder jQuery Plugin
$.fn.inputPlaceholder = function(options){
return $(this).each(function() {
var options = jQuery.extend({
text: $(this).attr('placeholder')
},options);
if($(this).val() == '') {
$(this).val(options.text);
}
$(this)
@radius
radius / urlparams.js
Created July 30, 2012 16:08
Get URL Query String Parameters with Javascript
var urlParams = (function () {
var _params={},
e,
a = /\+/g, // Regex for replacing addition symbol with a space
r = /([^&=]+)=?([^&]*)/g,
d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
q = window.location.search.substring(1);
while (e = r.exec(q)) {
_params[d(e[1])] = d(e[2]);
@radius
radius / Default.sublime-theme
Created November 5, 2012 22:58
My Sublime Text 2 default theme (Packages/Theme - Default/Default.sublime-theme)
[
{
"class": "label_control",
"color": [255, 255, 255],
"shadow_color": [24, 24, 24],
"shadow_offset": [0, -1]
},
{
"class": "button_control",
"content_margin": [6, 5, 6, 6],
@radius
radius / isOnScreen.jqery.js
Created August 20, 2013 18:48
jquery function to tell if a dom element is within the viewport
$.fn.isOnScreen = function(){
var win = $(window);
var viewport = {
top : win.scrollTop(),
left : win.scrollLeft()
};
viewport.right = viewport.left + win.width();
viewport.bottom = viewport.top + win.height();
var bounds = this.offset();
https://jsfiddle.net/#&togetherjs=15bbxQITu0
@radius
radius / premailer_app.py
Created December 12, 2016 20:41
Premailer Usage
import premailer
def parse_template_tags(input_str):
""" Premailer encodes paths in the src attribute of images, so we have to swap them out w original values here """
mapping = (
('%7B%7B%20', '{{ '), ('%20%7D%7D', ' }}'),
('%7B%7B', '{{ '), ('%7D%7D', ' }}'),
)
for k, v in mapping:
@radius
radius / TodoListApp.jsx
Created February 6, 2018 02:06
Todo React App
import React, { Component } from 'react';
import './App.css';
class App extends Component {
render() {
return (
<TodoList />
)
}
}
@radius
radius / xhr.html
Created February 27, 2018 01:59
XHR Example
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Simple XHR Example</title>
<script type="text/javascript">
function reqListener () {
var jsonResponse = JSON.parse(this.responseText);
var characters = jsonResponse.data.results;