Skip to content

Instantly share code, notes, and snippets.

View AlphaGit's full-sized avatar

Alpha AlphaGit

View GitHub Profile
@AlphaGit
AlphaGit / question.markdown
Last active February 13, 2017 02:19
Protractor and Travis, cross-platform scripts

(Note: this post was originally a question in StackOverflow, but has been removed as the question received no answers or activity in over a year, and was deemed an abandoned question.)

Protractor and Travis, cross-platform scripts

"...and other horror stories."

I've been trying for the past few days to get this to work with no luck. As such, I have a long story to tell but I'll break it down to parts so that it is easier to understand.

My goal:

@AlphaGit
AlphaGit / BigArray.cs
Last active May 24, 2017 11:43
BigArray.cs -- Allowing more than Int32.MaxValue elements in an array
namespace SomeLargeDataHolder
{
// adapted from https://blogs.msdn.microsoft.com/joshwil/2005/08/10/bigarrayt-getting-around-the-2gb-array-size-limit/
// Goal: create an array that allows for a number of elements > Int.MaxValue
class BigArray<T>
{
// These need to be const so that the getter/setter get inlined by the JIT into
// calling methods just like with a real array to have any chance of meeting our
// performance goals.
@AlphaGit
AlphaGit / titanic tree.markdown
Last active July 29, 2017 18:25
Decision tree breakdown of the Titanic survivor data
@AlphaGit
AlphaGit / CleanupDocker.ps1
Last active September 2, 2017 23:13
Cleanup docker
$ErrorActionPreference = "SilentlyContinue"
kill -force -processname 'Docker for Windows', com.docker.db, com.docker.slirp, com.docker.proxy, com.docker.9pdb, moby-diag-dl, dockerd
kill -force -processname com.docker.service
try {
pushd "C:\Program Files\Docker\Docker\Resources"
./MobyLinux.ps1 -Destroy
popd
} Catch {}
@AlphaGit
AlphaGit / badExample.js
Last active September 13, 2017 14:09
Good code / bad code: bad code
function checkOutCart(session, cb) { // this is the code that executes on checkout
getUserInfo(session.userId, function(err, user) { // it'll get the user information
if (err) { return cb(err); } // if it has any error, it will call back with it
if (user.hasDiscountedProfile) { // if the user has a profile for discounts
retrieveDiscount(user.profileId, function(err, discAmt) { // it will retrieve that discount
if (err) { return cb(err); } // on error, it aborts the operation
session.cart.addDiscount(discAmt); // adds the discount to the cart
getPaymentScreenConfig(function(err, payScrCfg) { // it retrieves the configuration from the payment screen
if (err) { return cb(err); } // on error, it aborts
cb(null, new PaymentScreen(payScrCfg, session.cart)); // creates a payment scree
@AlphaGit
AlphaGit / goodExample.js
Created September 13, 2017 14:09
Good code / bad code: good code
function checkoutCart(session) { // this is the code that executes on checkout
trackActivity(session, ACTIONS.CHECKED_OUT); // it tracks that the user is checking out
return getUserInfo(session.userId) // gets the user info with the user id
.then(user => getDiscountAmount(user)) // then it gets the discount for the user
.then(discAmt => addDiscountIfAny(session, discAmt)) // then it applies the discount
.then(getPaymentScreenConfig) // then it gets the payment screen configuration
.then(payScrCfg => new PaymentScreen(payScrCfg, session.cart)); // and it returns the payment screen
}
function getDiscountAmount(user) { // this is the code that gets the discount amount
@AlphaGit
AlphaGit / crontab
Last active November 5, 2017 17:13
Executing worklogger
# log hours to destination systems each day at noon
0 12 * * * /home/myUser/scripts/log-daily-hours.sh
# generate monthly report of worklogs each month, 1st day at 8 AM
0 8 1 * * /home/myUser/scripts/log-monthly-hours.sh
@AlphaGit
AlphaGit / generate_post.py
Created July 29, 2018 18:13
Generating shitposts from tumblr/Gutenberg corpora
import markovify
import tumblr_client
import settings
import re
import nltk
class NltkText(markovify.Text):
def word_split(self, sentence):
words = re.split(self.word_split_pattern, sentence)
if words[0] != "":
@AlphaGit
AlphaGit / load_tumblr_posts.py
Created July 29, 2018 18:18
Loading tumblr posts
# inspired in https://github.com/veggiedefender/miraculousladybot/blob/master/log.py
import requests
import re
import tumblr_client
from html2text import html2text
from datetime import datetime
from settings import blogs_to_search, posts_per_blog, tags_to_search, posts_per_search
@AlphaGit
AlphaGit / tumblr_client.py
Created July 29, 2018 18:21
Tumblr API client example
import requests
import oauth2
import urllib
from settings import auth
def get(url):
request = requests.get(url)
json = request.json()
response = json['response']