This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Cartesian product of input (for Integers) | |
//similar to itertools.product in Python | |
def l = [ [1,2] , [3,4] , [5, 6]] | |
def product(l){ | |
def p = { l1, l2 -> | |
l1.inject([]) { acc, i -> | |
acc + l2.inject([]) { acc1, j -> | |
if ( i instanceof List) { acc1 << i + j} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; This gist roughly transribes the demo | |
;; by Jim Weirich during his talk on Y-Combinator | |
;; called Y-Not. | |
;; http://www.infoq.com/presentations/Y-Combinator | |
;; Jim does a phenomenal job of explaining in the demo. | |
;; Therefore, this gist only attempts to provide | |
;; the code example from the poor quality video | |
;; The examples are simplified at some places | |
;; based on how I tried to understand it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Accepts a closure that takes one argument. The closure should return true/false. | |
//The closure is the predicate which will be checked to create new partitions | |
def partition(coll, Closure cond) { | |
def x = coll.drop(1).inject([[coll[0]]]) { acc, it -> | |
if ( cond(it) ) { | |
acc << [it] | |
} | |
else | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// code generated from <org.scribe.extractors.TokenExtractorTest: void shouldExtractTokenFromOAuthStandardResponse()> | |
com.ser.assist.statecarver.xstreamcarver.StaticStateLoader.loadStaticState(760, "scribe-java_freqT") | |
def dbName_intg = "scribe-java_freqT_intg" | |
temp$0 = com.ser.assist.statecarver.xstreamcarver.XStreamStateCarver.loadState(760, 200, "scribe-java_freqT") | |
temp$0_clone = com.ser.assist.statecarver.xstreamcarver.XStreamStateCarver.loadState(760, 200, "scribe-java_freqT") | |
response = com.ser.assist.statecarver.xstreamcarver.XStreamStateCarver.loadState(760, 0, "scribe-java_freqT") | |
//Note that we are using a 'response' object which was tested as part of unit test elsewhere. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
class InsertContext(): | |
def __init__(self, tf): | |
self._tf = tf | |
self.__write_mode_on = False | |
def __enter__(self): |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyodbc | |
# This will be the query to run | |
sql = 'SELECT * FROM AAF_IS_USER' | |
# conn_str = Here repace USER with treussard and YOUR_PASSWORD with the actual password |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
def foo(x, y, z): | |
return (x != y and x != z or x and z) | |
def get_test_args(): | |
x = y = z = [True, False] | |
from itertools import product, repeat | |
input_args = list(product(x, y, z)) | |
expected_args = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Adapted from http://chrisdone.com/posts/data-typeable | |
recordShow :: Data a => a -> ShowS | |
recordShow = render `extQ` (shows :: String -> ShowS) where | |
render t | |
| isTuple = drop 1 . tupleSlots | |
| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- sequence a state monad | |
import Control.Monad.Trans.State | |
-- Example 1 | |
let y = do { z <- get; let a = (Prelude.last z) + 1 in put (z Prelude.++ [a]);return $ (Prelude.last z) + 1} :: State [Int] Int | |
runState (sequenceA [y,y,y]) $ [1] | |
-- Example: 2 | |
type X = State (M.Map String Int) Int | |
let y s s1 = do { z <- get; let a = z M.! s + 1 in put (M.insert s1 a z) ; let a = z M.! s + 1 in return $ a } :: X |