Skip to content

Instantly share code, notes, and snippets.

View hernamesbarbara's full-sized avatar

austin hernamesbarbara

View GitHub Profile
#!/usr/bin/osascript
(* subroutine to bring an application to front.
you could invoke it from an alias in your
~/.bash_profile, another script or an alfred workflow
*)
property default_app : ""
on bring_to_front(app_name)
set res to false
@hernamesbarbara
hernamesbarbara / select_star_in_salesforce_apex.cls
Created November 20, 2014 22:47
Salesforce won't let you select star (SELECT *). This is a workaround where you generate the SOQL manually by inspecting the schema of the table.
Map<String, Schema.SObjectField> field_objmap = schema.SObjectType.Opportunity.fields.getMap();
List<Schema.SObjectField> field_objmap_values = field_objmap.values();
List<String> field_names_list = new List<String>();
for(Schema.SObjectField s : field_objmap_values) {
String field_label = String.valueOf(s.getDescribe().getLabel()); // Perhaps store this in another map
String field_name = String.valueOf(s.getDescribe().getName());
String field_type = String.valueOf(s.getDescribe().getType());
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""atbash.py
"""
from string import letters
def atbash(txt):
sub_table = zip(letters[:26], "".join(reversed(letters[:26])))
sub_table += zip(letters[26:], "".join(reversed(letters[26:])))
sub_table = dict(sub_table)
@hernamesbarbara
hernamesbarbara / .inputrc
Created February 29, 2012 05:03
search bash history quickly
#!/bin/bash
set completion-ignore-case on
#use up arrow to search history backwards
"\e[A": history-search-backward
"\e[B": history-search-forward
$if Bash
Space: magic-space
$endif
@hernamesbarbara
hernamesbarbara / PostgreSQL_Query.R
Created July 6, 2012 13:11
how to connect to a postgreSQL database from R
library(RPostgreSQL) #import the library
driver <- dbDriver('PostgreSQL') #define the database driver
db <- dbConnect(driver, host='foobar_host', #set the host to the postgreSQL IP or alias
user='foo_bar', #input username
password='my_secret_code', #input your password
dbname='my_gp_db') #input the name of the databse
myquery <- "SELECT
@hernamesbarbara
hernamesbarbara / google_regex.md
Created October 10, 2012 18:39
google regular expression helpers
#extract words in parens from a string
value.match(/(.+)\((.*)\)(.+)/)[1].split(' ')[1]

#replace the following characters with empty string:  , .  - ( )
toUppercase(value).replace(/\,|\.|\-|\(|\)|\[|\]/, '')

Keybase proof

I hereby claim:

  • I am hernamesbarbara on github.
  • I am hernamesbarbara (https://keybase.io/hernamesbarbara) on keybase.
  • I have a public key whose fingerprint is 8D83 4863 3195 7A45 4D2C 9BEF BE6B 90F3 C6E1 8518

To claim this, I am signing this object:

@hernamesbarbara
hernamesbarbara / pandas_na_cheatsheet.py
Created October 31, 2012 15:42
handle NA values in pandas
#/usr/bin/env python
# Handling NA values in pandas
import pandas as pd
# replace all NA values with your own missing value
my_data_frame['my_column'].fillna('MY_MISSING_VAL')
# return a subset of your dataframe
@hernamesbarbara
hernamesbarbara / select_rows_pandas.py
Created January 11, 2013 16:53
selecting data in pandas
import numpy as np
import pandas as pd
# look at free reports
free = df[df.report_name.isin(free)]
# look at paid reports only
paid = df[df.report_name.apply(lambda x: x not in free)]
from yhat import Yhat, BaseModel
from sklearn import datasets
from sklearn.svm import SVC
class IrisModel(yhat.BaseModel):
def transform(self, data):
data = [
data['SepalLength'],
data['SepalWidth'] / 2.0,
data['PetalLength'],