Skip to content

Instantly share code, notes, and snippets.

View primaryobjects's full-sized avatar

Kory Becker primaryobjects

View GitHub Profile
@primaryobjects
primaryobjects / RememberCellPosition.gs
Created April 2, 2015 17:40
Google Spreadsheet script to remember the last edited cell position and automatically scroll to it when opening the document.
//
// Remember Last Edited Cell Position in Google Spreadsheets
//
// Install:
// 1. Open spreadsheet in Google Drive.
// 2. Click Tools->Script editor.
// 3. Paste the contents of this file into the text field.
// 4. Click Run->install
// 5. When prompted for permission, click OK.
// 6. Click Run->install a second time. Done!
@primaryobjects
primaryobjects / singaporemathquiz.R
Last active August 29, 2015 14:19
Solution to the Singapore Math Problem (also called Cheryl's birthday' logic problem), found at http://www.nytimes.com/2015/04/15/science/a-math-problem-from-singapore-goes-viral-when-is-cheryls-birthday.html
# Kory Becker
# http://primaryobjects.com/kory-becker
# 4/2015
#
# This program solves the Singapore Math Problem, found at http://www.nytimes.com/2015/04/15/science/a-math-problem-from-singapore-goes-viral-when-is-cheryls-birthday.html
# The problem is a logic question, where you must deduce the correct birthday from a conversation with two people. The answer is determined through a series of elimination.
# Demo: http://www.r-fiddle.org/#/fiddle?id=8zUu1GdT&version=4
#
# Original problem:
# Albert and Bernard just met Cheryl. "When’s your birthday?" Albert asked Cheryl.
@primaryobjects
primaryobjects / saveChart.R
Last active October 9, 2021 02:21
Add text outside the chart area of a ggplot2 graph in R and save the resulting chart to a png file.
require(ggplot2)
require(gridExtra)
saveChart <- function(chart, fileName) {
# Draw attribution.
chart <- chart + geom_text(aes(label = 'sentimentview.com', x = 2.5, y = 0), hjust = -2, vjust = 6, color="#a0a0a0", size=3.5)
# Disable clip-area.
gt <- ggplot_gtable(ggplot_build(chart))
gt$layout$clip[gt$layout$name == "panel"] <- "off"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BinaryTree
{
public class Node
{
@primaryobjects
primaryobjects / atest.js
Created June 1, 2015 15:22
Example of running LDA on Wikipedia article, using node.js lda library https://github.com/primaryobjects/lda.
var lda = require('lda'),
fs = require('fs');
// Read document (source from random Wikipedia page http://en.wikipedia.org/wiki/Harry_Anderson).
fs.readFile('doc.txt', 'utf8', function(err, data) {
if (err) {
throw err;
}
else {
// Extract sentences.
@primaryobjects
primaryobjects / readme.txt
Last active November 9, 2022 12:14
2 Ways to Return Multiple Values with sapply in R
2 Ways to Return Multiple Values with sapply
---
Demo at http://www.r-fiddle.org/#/fiddle?id=4pR9ndzC&version=2
Assume we have the following data:
Date Value
1 2015-05-01 73
2 2015-05-01 94
@primaryobjects
primaryobjects / readme.txt
Last active August 29, 2015 14:23
Declaring an enum with a getter and no setter compiles in VS2015, but no in VS2013.
Why does this code compile in Visual Studio 2015, but not in Visual Studio 2013? Hmmm?
------
VS2013:
'EnumTest.Dude.thing.get' must declare a body because it is not marked abstract or extern. Automatically implemented properties must define both get and set accessors.
@primaryobjects
primaryobjects / refreshTooltips.js
Last active August 29, 2015 14:23
Fix for Zurb Foundation CSS with AngularJs to properly update tooltips when their text is dynamically changed. Basically, this replaces: $(document).foundation('tooltip', 'reflow');
function refreshTooltips() {
// Foundation does not update tooltips from angular dynamically, so we have to rebuild them manually.
// Foundation tooltips consist of your added span tag with the tooltip text and a dynamic property "data-selector", which points to the tooltip popover element.
// We loop over all tooltip span tags and update their cooresponding popover layer with the span title text.
$('span[data-tooltip]').each(function () {
// Found a tooltip span tag.
var e = $(this);
var id = e.data('selector');
var text = e.attr('title');
@primaryobjects
primaryobjects / app.js
Last active August 29, 2015 14:24
Steps to deploy a node.js app on RedHat OpenShift: In app.js, call app.set() for the port and ip. In packages.json, set "main": "app.js"
app.configure(function() {
// Set the IP and port to use the OpenShift variables.
app.set('port', process.env.OPENSHIFT_NODEJS_PORT || process.env.OPENSHIFT_INTERNAL_PORT || process.env.PORT || 3000);
app.set('ip', process.env.OPENSHIFT_NODEJS_IP || process.env.OPENSHIFT_INTERNAL_IP || 'localhost');
});
// ...
// Set the app.listen to use the port and ip.
app.listen(app.get('port'), app.get('ip'), function(){
@primaryobjects
primaryobjects / csv-split.bf
Last active August 29, 2015 14:25
This code was written by an AI https://github.com/primaryobjects/AI-Programmer. Splits text at every 3-characters by a comma (creating a CSV string).
>>,.,[.,.[<]++++++++++++++++++++++++++++++++++++++++++++.,.,]