Skip to content

Instantly share code, notes, and snippets.

Chienyi Cheri Hung cherihung

View GitHub Profile
View es6utils.js
const compose = (...functions) => x => functions.reduce((acc, fn) => fn(acc), x);
// compose(fn1, fn2, fn3)
const pipe = functions => data => {
return functions.reduce(
(value, func) => func(value),
data
);
};
@cherihung
cherihung / generate_min_hours.js
Last active Jul 21, 2017
generate string array of time units
View generate_min_hours.js
const _generator = i => {
return i < 9 ? '0'+(i+1) : (i+1).toString();
};
const UNITS = Array.from({length: 60}, (v, i) => {
return _generator(i);
});
@cherihung
cherihung / check-for-current.html
Last active Jun 25, 2017
for jekyll templates - determine if item in menu is the current one navigated to
View check-for-current.html
{% for item in sorted_items %}
{% assign current = nil %}
{% if page.id == item.url %}
{% assign current = 'currentItem' %}
{% endif %}
<li class="{{current}}"><a href="{{item.url}}"><img src="{{item.imageId}}.jpg" /></a></li>
{% endfor %}
@cherihung
cherihung / csv-to-mkdown-files.py
Last active Jun 25, 2017
convert each row in csv to a markdown file in python
View csv-to-mkdown-files.py
import csv
def toMarkdown(item):
newTemp = "---"+"\n"+"layout: sculpture"+"\n"+"pageId: "+item[0]+"\n"+"uid: "+item[1]+"\n"
newTemp += "title: "+item[2]+"\n"+"location: "+item[3]+"\n"+"completionDate: "+item[4]+"\n"
newTemp += "description: "+item[5]+"\n"+"imageId: "+item[6]+"\n"
newTemp += "---"+"\n"
return newTemp
with open('file.csv', 'rb') as f:
View findMethods.js
R.find(function(w) {return item[key] === w[key];}, collection);
R.find(function(w) {return item === w.id;}, collection);
function(key, collection, item) {
var found = _.find(collection, function(x) {
return x[key] === item[key];
});
return found;
}
View functionalDeferredPattern.js
var _deferredFetch = r.curry(function(response) {
var deferred = $q.defer();
deferred.resolve(response);
return deferred.promise;
});
@cherihung
cherihung / deferredPromisesPattern.js
Created Feb 16, 2016
Pattern for collection deferred promises at once
View deferredPromisesPattern.js
function fetchFromService(data) {
var promises = [];
_.each(data, function(item) {
var deferred = $q.defer();
someService.getItem(item).then(function(response) {
deferred.resolve(response);
});
promises.push(deferred.promise);
});
return $q.all(promises);
View sceFilter.js
angular.module('sceTrustfilter', []).filter('html_to_trust', ['$sce', function($sce){
return function(text) {
return $sce.trustAsHtml(text);
};
}]);
View makesandwich.py
def makeSand(haspb, hasjelly, slicesofbread):
breadneeded = 2.0
if haspb == True: #have peanut butter
numofsand = slicesofbread/breadneeded #calculate number of sandwich I can make from bread
sandtype = "peanut butter" #set default sandwich type
if hasjelly == True: #have jelly too
sandtype = "peanut butter and jelly" #set sandwich type to include jelly
#start counting number of sandwiches I can make
@cherihung
cherihung / wp-prevnext.php
Created Aug 4, 2013
create prev/next nav for custom post type. something that works like this plugin http://wordpress.org/plugins/previous-and-next-post-in-same-taxonomy/ but can offer order by menu order
View wp-prevnext.php
//from this post http://bucketpress.com/next-and-previous-post-link-in-same-custom-taxonomy
// get_posts in same custom taxonomy
$postlist_args = array(
'posts_per_page' => -1,
'orderby' => 'menu_order title',
'order' => 'ASC',
'post_type' => 'your_custom_post_type',
'your_custom_taxonomy' => 'your_custom_taxonomy_term'
);
$postlist = get_posts( $postlist_args );
You can’t perform that action at this time.