Skip to content

Instantly share code, notes, and snippets.

@czarrar
czarrar / 0_reuse_code.js
Created September 25, 2013 02:49
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@czarrar
czarrar / html_to_readability.rb
Created October 3, 2013 04:30
Bookmark a webpage to readability
#!/usr/bin/env ruby
# WHAT WE DO HERE
# Take a link
# Add it as a bookmark
# Two inputs needed
if ARGV.count != 4
abort "$0 username email password weblink"
end
#!/usr/bin/env ruby
# Four inputs needed
if ARGV.count != 4
abort "$0 username email password article-id"
end
username = ARGV[0]
email = ARGV[1]
password = ARGV[2]
id = ARGV[1]
@czarrar
czarrar / cwas_bootstrap.R
Created October 26, 2013 01:16
Bootstrap Analysis of CWAS
library(connectir)
library(boot)
# data = model
boot_mdmr <- function(formula, data, indices, sdist, factors2perm) {
###
# Distances
###
# We need to sample the distances based on the indices
import sys
#sys.path.append("/Users/zarrar/Dropbox/Code/C-PAC/CPAC/cwas")
sys.path.insert(0, "/home2/data/Projects/CPAC_Regression_Test/2013-05-30_cwas/C-PAC/CPAC/cwas")
sys.path.append("/home/data/PublicProgram/epd-7.2-2-rh5-x86_64/lib/python2.7/site-packages")
import multiprocessing
import numpy as np
from mdmr import mdmr
from sklearn.metrics.pairwise import euclidean_distances
@czarrar
czarrar / 1_compare_eigenvectors.py
Last active December 31, 2015 06:49
This script compares different approaches to calculating eigenvector centrality. It finds that when using normalized matrices, there are differences between the output of the methods, whereas when using non-normalized matrices, the outputs of the methods are the same. The last script is from the fast eigenvector centrality code on bias.googlecod…
import numpy as np
from CPAC.cwas.subdist import norm_cols
from fast_ecm import fast_eigenvector_centrality # this is from the other gist; can ignore this and paste in the other function
print 'Compare with non-normalized matrices'
m = np.random.random((200,1000))
cm = m.T.dot(m)
# Let's first call a basic approach
@czarrar
czarrar / python_resources.md
Created December 20, 2013 15:24 — forked from jookyboi/python_resources.md
Python-related modules and guides.

Packages

  • lxml - Pythonic binding for the C libraries libxml2 and libxslt.
  • boto - Python interface to Amazon Web Services
  • Django - Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.
  • Fabric - Library and command-line tool for streamlining the use of SSH for application deployment or systems administration task.
  • PyMongo - Tools for working with MongoDB, and is the recommended way to work with MongoDB from Python.
  • Celery - Task queue to distribute work across threads or machines.
  • pytz - pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.4 or higher.

Guides

@czarrar
czarrar / rails_resources.md
Created December 20, 2013 15:24 — forked from jookyboi/rails_resources.md
Rails-related Gems and guides to accelerate your web project.

Gems

  • Bundler - Bundler maintains a consistent environment for ruby applications. It tracks an application's code and the rubygems it needs to run, so that an application will always have the exact gems (and versions) that it needs to run.
  • rabl - General ruby templating with json, bson, xml, plist and msgpack support
  • Thin - Very fast and lightweight Ruby web server
  • Unicorn - Unicorn is an HTTP server for Rack applications designed to only serve fast clients on low-latency, high-bandwidth connections and take advantage of features in Unix/Unix-like kernels.
  • SimpleCov - SimpleCov is a code coverage analysis tool for Ruby 1.9.
  • Zeus - Zeus preloads your Rails app so that your normal development tasks such as console, server, generate, and specs/tests take less than one second.
  • [factory_girl](h
@czarrar
czarrar / easy_functional_density.py
Last active January 3, 2016 22:29
Do some quick functional density mapping for a sample voxel. Note this code assumes you are running off rocky.
import numpy as np
import os
#from CPAC.network_centrality import load
#from CPAC.cwas.subdist import norm_cols
import nibabel as nib
from scipy.sparse import coo_matrix, cs_graph_components
def load(datafile, template):
@czarrar
czarrar / cpac_centrality.py
Last active August 29, 2015 14:01
Calculates degree centrality using CPAC code
#!/usr/bin/env python
import argparse
import os
from os import path
from CPAC.network_centrality import calc_centrality
###