Skip to content

Instantly share code, notes, and snippets.

View cstephe's full-sized avatar

Chris Stephens cstephe

View GitHub Profile
@btm1
btm1 / set-attr
Last active February 22, 2016 09:59
Set attribute is a directive that takes an object and evaluates each property where the key is the attribute you want to set and the value is the value for that attribute i.e. set-attr="{ data-id : post.id, data-name : post.name }" Additionally if the value for each key can also be an object with two properties "condition" and "value" where cond…
angular.module('setAttr',[]).directive('setAttr', function() {
return {
restrict: 'A',
priority: 100,
link: function(scope,elem,attrs) {
if(attrs.setAttr.indexOf('{') != -1 && attrs.setAttr.indexOf('}') != -1) {
//you could just angular.isObject(scope.$eval(attrs.setAttr)) for the above but I needed it this way
var data = scope.$eval(attrs.setAttr);
angular.forEach(data, function(v,k){
@btm1
btm1 / set-if
Created October 2, 2013 23:51
set-if will conditionally show or hide elements in the DOM once and will not apply a $watch listener. An additional attribute (wait-for) can be applied to the element to wait for data to be populated before evaluating the if statement i.e. <div set-if="should.behere" wait-for="should"></div>
angular.module('setIf',[]).directive('setIf',function () {
return {
transclude: 'element',
priority: 1000,
terminal: true,
restrict: 'A',
compile: function (element, attr, linker) {
return function (scope, iterStartElement, attr) {
if(attr.waitFor) {
var wait = scope.$watch(attr.waitFor,function(nv,ov){
@eric-hu
eric-hu / Open iterm tab here
Last active March 11, 2022 02:45
Apple script to open an iterm2 tab from right-clicking on a file or folder in Finder. To use: (1) Open Automator (2) Create a new service (3) Change "Service receives selected" drop downs to "Files or folders" in "Finder" (4) Select "Run applescript" from the sidebar, then paste this script in and save
-- Adapted from these sources:
-- http://peterdowns.com/posts/open-iterm-finder-service.html
-- https://gist.github.com/cowboy/905546
--
-- Modified to work with files as well, cd-ing to their container folder
on run {input, parameters}
tell application "Finder"
set my_file to first item of input
set filetype to (kind of (info for my_file))
-- Treats OS X applications as files. To treat them as folders, integrate this SO answer:
@ttezel
ttezel / quickSort.js
Created July 16, 2012 19:10
Simple QuickSort in JS
function quickSort (arr) {
if (!arr.length)
return arr
var pivot = arr.splice(0, 1)
var less = []
var greater = []
arr.forEach(function (el) {
if (el <= pivot)