Skip to content

Instantly share code, notes, and snippets.

View cherihung's full-sized avatar

Cheri Hung cherihung

View GitHub Profile
@cherihung
cherihung / csv-to-mkdown-files.py
Last active April 20, 2022 06:32
convert each row in csv to a markdown file in python
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:
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;
}
var _deferredFetch = r.curry(function(response) {
var deferred = $q.defer();
deferred.resolve(response);
return deferred.promise;
});
@cherihung
cherihung / deferredPromisesPattern.js
Created February 16, 2016 14:46
Pattern for collection deferred promises at once
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);
angular.module('sceTrustfilter', []).filter('html_to_trust', ['$sce', function($sce){
return function(text) {
return $sce.trustAsHtml(text);
};
}]);
@cherihung
cherihung / makesandwich.py
Last active December 25, 2015 09:19
functionize.
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 August 4, 2013 23:23
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
//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 );
@cherihung
cherihung / speechBubble.css
Created July 31, 2013 19:44
speech bubble, plain
.bubble {
position:relative;
padding:10px;
margin:1em 0;
color:#000;
line-height: 1.65em;
font-weight: 500;
background:#EDE4A6;
-webkit-border-radius:10px;
-moz-border-radius:10px;
@cherihung
cherihung / smoothScroll-simple.js
Last active December 20, 2015 09:40
smooth scroll using jquery. a sample snippet that targets one defined href.
jQuery(document).ready(function(){
var dpost = jQuery('#calloutpos').offset().top;
jQuery('#bottomslide').click(function(){
jQuery('html, body').animate({scrollTop:dpos}, 'slow');
return false;
});
});
@cherihung
cherihung / translate-csv-to-d3nest.js
Created July 3, 2013 16:02
Translate data from CSV to d3nest style data objects, when d3.nest() does not produce the desire objects. Or when you need to customize the returned objects for any reason, the class function is handy.
function drawMap(id, ds) {
//load data
d3.csv(ds, function(data) {
var nodes = classes(data);
for (var i=0;i<1;i++){
d3.select('#'+id)
.selectAll('#'+id+' li')