type StringBool = "true"|"false";
interface AnyNumber { prev?: any, isZero: StringBool };
interface PositiveNumber { prev: any, isZero: "false" };
type IsZero<TNumber extends AnyNumber> = TNumber["isZero"];
type Next<TNumber extends AnyNumber> = { prev: TNumber, isZero: "false" };
type Prev<TNumber extends PositiveNumber> = TNumber["prev"];
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
| def convert(sqlContext: SQLContext, filename: String, schema: StructType, tablename: String) { | |
| // import text-based table first into a data frame. | |
| // make sure to use com.databricks:spark-csv version 1.3+ | |
| // which has consistent treatment of empty strings as nulls. | |
| val df = sqlContext.read | |
| .format("com.databricks.spark.csv") | |
| .schema(schema) | |
| .option("delimiter","|") | |
| .option("nullValue","") | |
| .option("treatEmptyValuesAsNulls","true") |
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
| // Logs all calls to preventDefault / stopPropagation in an user-friendly way | |
| if ( process.env.NODE_ENV !== "production" ) { | |
| (function monkeyPatchEventMethods() { | |
| const logEventMethodCall = (event,methodName) => { | |
| const MinimumMeaninfulSelectors = 3; // how much meaningful items we want in log message | |
| const target = event.target; | |
| const selector = (function computeSelector() { |
This is an example of how to process data in hierarchical structures using either recursion or a stack based approach. To examplify this we will use a didactical example: find the maximum number in an array of arrays. The same techniques can be used to find / process data in other hierarchical structure such as XML documents, JSON objects, etc.
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
| # first: mkdir user && cd user && cp /path/to/get_gists.py . | |
| # python3 get_gists.py user | |
| import requests | |
| import sys | |
| from subprocess import call | |
| user = sys.argv[1] | |
| r = requests.get('https://api.github.com/users/{0}/gists'.format(user)) |
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
| // Taken from http://developers.marketo.com/blog/restrict-free-email-domains-on-form-fill-out/ | |
| // Prepared by Ian Taylor and Murtza Manzur on 9/9/2014 - Modified Dillan Simmons 8/15/17 | |
| (function (){ | |
| // Please include the email domains you would like to block in this list | |
| var invalidDomains = ["@gmail.","@yahoo.","@hotmail.","@live.","@aol.","@outlook.","@test."]; | |
| MktoForms2.whenReady(function (form){ | |
| form.onValidate(function(){ | |
| var email = form.vals().Email; |
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
| // Dave's AMPScript cheat sheet. | |
| // AMPScript is ExactTarget (SFDC Marketing Cloud)'s server side scripting language. | |
| // It's a bit of a pig, plus the docs are numerous and the examples aren't contextual. | |
| // This assumes you don't need hand holding, and just need to get your head around it. | |
| // It's also my reference for the snippets I use all the time (I'm a formatting stickler). | |
| // These examples come from microsites I've written - adapt 'em for use elsewhere. | |
| // Multi line AMPScript %%[contained within delimiters]%% gets interpreted on the server. |
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
| COUNTRIES_WITHOUT_POSTCODES = [ | |
| [ "Angola", "AO" ], | |
| [ "Antigua and Barbuda", "AG" ], | |
| [ "Aruba", "AW" ], | |
| [ "Bahamas", "BS" ], | |
| [ "Belize", "BZ" ], | |
| [ "Benin", "BJ" ], | |
| [ "Bolivia", "BO" ], | |
| [ "Botswana", "BW" ], | |
| [ "Burkina Faso", "BF" ], |
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
| # -*- coding: utf-8 -*- | |
| import os | |
| import StringIO | |
| import hashlib | |
| try: | |
| from boto.s3.connection import S3Connection | |
| from boto.s3.key import Key | |
| except ImportError: | |
| raise ImproperlyConfigured, "Could not load Boto's S3 bindings." |
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
| # https://codereview.stackexchange.com/questions/200870/powershell-script-to-deploy-repository-to-salesforce | |
| param([string] $repositoryDirectory, [bool] $isProduction) | |
| # TODO - git integration. Select a branch and check it out for deploy. | |
| # TODO - break stuff into functions and reusable pieces. ¿piping? ¿cmdlets? | |
| # TODO - Allow directory structures? | |
| Write-Host -ForegroundColor green ":: Validating Repository ::" | |
| $srcDirectory = [System.IO.Path]::Combine($repositoryDirectory, "src") |