Skip to content

Instantly share code, notes, and snippets.

View mkim0710's full-sized avatar

mkim0710 mkim0710

View GitHub Profile
@dsparks
dsparks / off_diagonal.R
Created September 10, 2012 19:17
Modifying select off-diagonal items in a matrix
# A method for modifying only select off-diagonal items in a matrix
# From "Thierry" and "Ben Bolker"
# At http://stackoverflow.com/a/11759744/479554
# A sample matrix
size <- 6
mat <- matrix(seq_len(size ^ 2), ncol = size)
print(mat)
# A companion matrix that indicates how "off" a diagonal is:
library(RColorBrewer)
library(colorRamps)
pdf("rcolorsheet.pdf", paper="a4r", width=11.6, height=8.2, onefile=TRUE)
### page 1
# grDevices::colors
m <- matrix(1:660, 60, 11)
@jknowles
jknowles / MWEblogpost.Rmd
Created May 27, 2013 22:30
R Markdown of blog post on R minimal working examples (MWE).
How to Ask for Help using R
========================================================
The key to getting good help with an R problem is to provide a minimally working
reproducible example (MWRE). Making an MWRE is really easy with R, and it will
help ensure that those helping you can identify the source of the error, and
ideally submit to you back the corrected code to fix the error instead of sending
you hunting for code that works. To have an MWRE you need the following items:
- a minimal dataset that produces the error
@SalGnt
SalGnt / force-rgb-mode-in-mac-os-x-to-fix-the-picture-quality-of-an-external-monitor.md
Last active July 5, 2023 19:30
Force RGB mode in Mac OS X to fix the picture quality of an external monitor.

Force RGB mode in Mac OS X to fix the picture quality of an external monitor (Original)

Update: I have heard that 10.8.3 has solved this problem for some people, so I rolled back my changes and installed the update. No change on my monitor. Nevertheless, it’d be a good idea to update OS X before trying this, since it may fix the issues with your particular hardware.

I recently bought a MacBook Pro (with ‘Retina’ screen), but when I hooked it up to my Dell U2410 monitor via HDMI cable I was shocked by the poor picture quality. The contrast was all wrong and text was misshapen. No amount of calibration in the monitor or software would fix it.

Short answer: OS X thinks my monitor is a TV, and is using the YCbCr colour space rather than RGB. I had to override an EDID setting to force the RGB colour space, and it is now working correctly.

Long answer: I haven’t owned a Mac for a while and h

@kevinushey
kevinushey / RcppMelt.md
Last active August 2, 2016 03:13
Implementing reshape2::melt in Rcpp.

Melting with Rcpp

A common data manipulation task is that of making 'wide' data 'long': for example, using the reshape2 library,

library(reshape2)
wide_df &lt;- data.frame( stringsAsFactors=FALSE,
#!/usr/bin/ruby
# Create display override file to force Mac OS X to use RGB mode for Display
# see http://embdev.net/topic/284710
require 'base64'
data=`ioreg -l -d0 -w 0 -r -c AppleDisplay`
edids=data.scan(/IODisplayEDID.*?<([a-z0-9]+)>/i).flatten
vendorids=data.scan(/DisplayVendorID.*?([0-9]+)/i).flatten
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# export from R to Excel with conditional highlighting
# see http://stackoverflow.com/questions/21618556/export-data-frames-to-excel-via-xlsx-with-conditional-formatting
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# get some data from the psych package
library(psych)
dat <- bfi
# load xlsx
library(xlsx)

This Gist contains the script and generated output file for an Acer B276HUL.

The pre-generated file below is known to work with:

  • OS X Mavericks
  • OS X Yosemite
  • OS X El Capitan

For El Capitan:

  1. Restart your Mac while holding Command-R: this puts your Mac into Recovery Mode.
@bquistorff
bquistorff / Stata-syntax-highlighting-notepad++.xml
Last active March 9, 2025 07:32
Notepad++ syntax highlighting file for Stata code
<NotepadPlus>
<UserLang name="Stata" ext="do ado" udlVersion="2.1">
<Settings>
<Global caseIgnored="yes" allowFoldOfComments="no" foldCompact="no" forcePureLC="2" decimalSeparator="0" />
<Prefix Keywords1="no" Keywords2="no" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="no" Keywords7="yes" Keywords8="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments">00// 00* 00/// 01 02 03/* 04*/</Keywords>
<Keywords name="Numbers, prefix1"></Keywords>
<Keywords name="Numbers, prefix2"></Keywords>
@stephenturner
stephenturner / microbenchmark-blog-post.R
Last active July 28, 2017 19:56
Code for GGD blog post on microbenchmark
# see blog post here:
# http://gettinggeneticsdone.blogspot.com/2015/01/microbenchmark-package-r-compare-runtime-r-expressions.html
library(dplyr)
library(nycflights13)
flights
# base
aggregate(flights$arr_delay, by=list(flights$carrier), mean, na.rm=TRUE)