Skip to content

Instantly share code, notes, and snippets.

@echo off
setlocal enabledelayedexpansion
REM Get the chosen branch as a variable (Default: current branch)
if [%2%]==[] (
git rev-parse --abbrev-ref HEAD > tmpFile
set /p git_branch=<tmpFile
del tmpFile
) else (
set git_branch=%2
@evenv
evenv / Spark Dataframe Cheat Sheet.py
Last active June 24, 2022 23:45
Cheat sheet for Spark Dataframes (using Python)
# A simple cheat sheet of Spark Dataframe syntax
# Current for Spark 1.6.1
# import statements
from pyspark.sql import SQLContext
from pyspark.sql.types import *
from pyspark.sql.functions import *
#creating dataframes
df = sqlContext.createDataFrame([(1, 4), (2, 5), (3, 6)], ["A", "B"]) # from manual data
@evenv
evenv / add_labels.py
Created December 25, 2014 21:59
add labels in gmail based on email info
import os, os.path, re
import httplib2
from email.Header import decode_header
from apiclient.discovery import build
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import run
@evenv
evenv / dump_outlook_csv.rb
Created July 8, 2012 07:45
Create a dump of all emails (title, from, to, date) from Outlook to CSV - great for statistics
require 'win32ole'
require 'CSV'
outlook = WIN32OLE.new('Outlook.Application')
m = outlook.GetNameSpace('MAPI')
def searchfolder(folder)
return if folder.defaultitemtype > 0 #only email folders
return if ["Deleted Items","Sync Issues","News Feed","RSS Feeds","Junk E-mail","SharePoint Lists"].member? folder.name
folderpath = folder.fullfolderpath.gsub("\\","-").gsub("--","")
@evenv
evenv / rook_forecast.R
Created July 2, 2012 22:26
R seasonal forecasting service in Rook
app <- function(env){
req <- Rook::Request$new(env)
res <- Rook::Response$new()
inputData <- gsub("##","\n",req$POST()[['data']])
write(inputData, file = "inputData.txt")
d <- read.table( "inputData.txt", sep=",", header=TRUE, row.names=1 )
d.startY <- as.integer( substr( row.names(d)[1], 1, 4 ) )
@evenv
evenv / vinoscan.rb
Created July 2, 2012 20:15
Scrape Vinmonopolet web site
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'sqlite3'
require 'iconv'
require 'HTMLEntities.rb'
class String
def to_iso
@evenv
evenv / exportPDF.applescript
Created July 2, 2012 20:13
Export All OmniGraffle Files In A Folder To PDF
tell application "Finder"
set the theFolder to choose folder with
"Pick a folder containing the OmniGraffle files you want to export to PDF:"
set theList to every file of the theFolder whose
name extension is "graffle"
end tell
repeat with theFile in theList
set theOutFile to ((do shell script "basename \"" & (theFile) & "\"" & " .graffle") & ".pdf")
@evenv
evenv / auto_unrar.rb
Created July 2, 2012 19:53
Automatically Unrar Everything In A Folder
def episode(dir)
dir.match "HDTV"
end
def unrar_delete(thefile,allfiles)
if system "/opt/local/bin/unrar e -y %s &gt; /dev/null" % thefile.gsub(' ',' ')
for file in allfiles
File.delete(file)
end
return true
@evenv
evenv / tumblr-gist.js
Created July 1, 2012 13:20 — forked from slezica/tumblr-gist.js
tumblr gist embedder - without class requirement
var real_docwrite = document.write,
body = $('body');
(function insertGists(a_tags) {
if (a_tags.length > 0) {
a_tag = a_tags.shift()
document.write = function(stylesheet) {
$('head').append(stylesheet);
@evenv
evenv / transform_sharepoint.xslt
Created July 1, 2012 12:43
transform sharepoint managed metadata into word cloud
<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:msxsl='urn:schemas-microsoft-com:xslt' exclude-result-prefixes='msxsl'>
<xsl:output method='html' indent='yes'/>
<xsl:template name='terms' match='//termset'>
<xsl:param name='d'/>
<div class='termset' style='padding: 10px 0px; text-align: center;'>
<xsl:variable name='AvgHit'><xsl:value-of select='sum(//term/itemcount) div count(//term[itemcount > 0])'/></xsl:variable>
<xsl:for-each select='//term[itemcount > 0]'>
<xsl:sort select='name'/>
<xsl:element name='span'>