Skip to content

Instantly share code, notes, and snippets.

View abeburnett's full-sized avatar

Abe Burnett abeburnett

  • Ogden, UT
View GitHub Profile
anonymous
anonymous / dbWriteTable.fast.R
Created May 12, 2011 13:00
Function to get problematic data into PostgreSQL from R (uses RPostgreSQL)
# Function to get data over to PostgreSQL quickly and with minimal loss
# of information due to data type conversions.
# Note that I have had cases where the pipe() call returned an error due
# to lack of memory. So care should be taken with this function
dbWriteTable.fast <- function (conn,name,value,row.names=FALSE,
overwrite=TRUE,fix.names=TRUE) {
# Conform names to PostgreSQL requirements
pg.names <- make.db.names(conn,names(value))
@tomtung
tomtung / saas-class-homework-ruby-basics.rb
Created March 4, 2012 15:30
SaaS Class Homework: Ruby Basics
# Homework 1 - Part 1
def palindrome?(string)
string = string.downcase.gsub(/\W/, '')
string == string.reverse
end
def count_words(string)
Hash[
string.downcase.scan(/\w+/).
group_by{|s| s}.
@fractastical
fractastical / client.js
Created June 3, 2012 15:21 — forked from matteoagosti/client.js
Twitter OAUTH using Meteorjs
var ClientRouter = Backbone.Router.extend({
routes: {
'404': 'notfound',
'500': 'error',
'auth': 'auth',
'authCallback?oauth_token=:oauth_token&oauth_verifier=:oauth_verifier': 'authCallback',
'': 'defaultRoute'
},
defaultRoute: function() {
@kyleondata
kyleondata / gist:3440492
Last active February 1, 2023 19:23
Backbone.js and Handlebars.js example
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8" />
<script src="jquery-1.7.2.min.js" ></script>
<script src="handlebars-1.0.0.beta.6.js" ></script>
<script src="underscore-min.js" ></script>
<script src="backbone-min.js" ></script>
@mjbommar
mjbommar / r_oracle_jdbc_example1.R
Created November 22, 2012 15:36
Example of connecting to an Oracle database using R and RJDBC
# Set JAVA_HOME, set max. memory, and load rJava library
Sys.setenv(JAVA_HOME='/path/to/java_home')
options(java.parameters="-Xmx2g")
library(rJava)
# Output Java version
.jinit()
print(.jcall("java/lang/System", "S", "getProperty", "java.version"))
# Load RJDBC library
@snipe
snipe / inputrc
Created April 17, 2013 16:44
~/.inputrc for nice bash history up-arrows. This allows you to search through your history using the up and down arrows … i.e. type "cd /" and press the up arrow and you'll search through everything in your history that starts with "cd /". Create ~/.inputrc and fill it with this:
"\e[A": history-search-backward
"\e[B": history-search-forward
set show-all-if-ambiguous on
set completion-ignore-case on
@tomasgreif
tomasgreif / RPostgreSQL_sqldf
Last active April 6, 2017 18:42
RPostgreSQL and sqldf basic usage
# www.analytikdat.cz
# www.analytikdat.cz/index.php/blog/entry/r-and-postgresql-using-rpostgresql-and-sqldf
# Load required libraries
library("RPostgreSQL")
library("sqldf")
# Establish connection
drv <- dbDriver("PostgreSQL")
# Simple version (localhost as default)
@benmarwick
benmarwick / colocates.r
Last active October 24, 2017 10:18
Analysis of collocation of words in a text with R. Extracts LHS and RHS collocates of a word of interest over a user-defined span. Calculates frequency of collocates and mean distances. Inspired by http://www.antlab.sci.waseda.ac.jp/software.html
# R code for basic collocation statistics on a text corpus.
# Extracts LHS and RHS collocates of a word of interest
# over a user-defined span. Calculates frequency of
# collocates and mean distances.
examp1 <- "When discussing performance with colleagues, teaching, sending a bug report or
searching for guidance on mailing lists and here on SO, a reproducible example is often
asked and always helpful. What are your tips for creating an excellent example? How do
you paste data structures from r in a text format? What other information should you
include? Are there other tricks in addition to using dput(), dump() or structure()?
@scaryguy
scaryguy / change_primary_key.md
Last active April 8, 2024 14:23
How to change PRIMARY KEY of an existing PostgreSQL table?
-- Firstly, remove PRIMARY KEY attribute of former PRIMARY KEY
ALTER TABLE <table_name> DROP CONSTRAINT <table_name>_pkey;
-- Then change column name of  your PRIMARY KEY and PRIMARY KEY candidates properly.
ALTER TABLE <table_name> RENAME COLUMN <primary_key_candidate> TO id;
@hmans
hmans / application.html.slim
Last active October 27, 2023 17:52
Application layout for Rails (4 and 5), Slim style.
doctype html
html
head
title My App
meta name="viewport" content="width=device-width, initial-scale=1.0"
= stylesheet_link_tag "application", media: 'all', 'data-turbolinks-track' => true
= javascript_include_tag "application", 'data-turbolinks-track' => true
= csrf_meta_tags
body