Skip to content

Instantly share code, notes, and snippets.

View marcolivierarsenault's full-sized avatar

Marc-Olivier Arsenault marcolivierarsenault

View GitHub Profile
//OpensCAD
car_diam = 63;
car_height = 90;
cup_diam = 74;
cup_height = 70;
wall = 2;
cup_floor = 3;
view = 0;
bill_height = 69.85;
bill_width = 152.4;
space = 3;
cutout = 25;
walls = 5;
view = 1;
import json
from botocore.vendored import requests
url = 'https://voyagesarabais.com/recherche-sud/getpricedetails?search%5Bgateway%5D=YUL&search%5BdateDep%5D=2019-12-15&search%5Bduration%5D=7day%2C8day&search%5BdestDep%5D=o&search%5BnoHotel%5D=p7&search%5Broom1%5D=a%3A4%3A%7Bi%3A0%3Bs%3A2%3A%2240%22%3Bi%3A1%3Bs%3A2%3A%2240%22%3Bi%3A2%3Bs%3A1%3A%223%22%3Bi%3A3%3Bs%3A1%3A%221%22%3B%7D&search%5Broom2%5D=&search%5Broom3%5D=&search%5Broom4%5D=&search%5Broom5%5D=&search%5Broom6%5D=&search%5Bflex%5D=N&search%5Bflexhigh%5D=3&search%5Bflexlow%5D=3&search%5Broomcallgroup%5D=%5B%7B%22_priority%22%3A9%2C%22nb_rooms%22%3A1%2C%22nb_adults%22%3A2%2C%22non_adults%22%3A%5B%223%22%2C%221%22%5D%7D%5D&search%5Bpricemax%5D=9000&search%5Bpricemin%5D=1&search%5Ballinclusive%5D=Y&search%5Bbeach%5D=&search%5Bcasino%5D=&search%5Bfamily%5D=&search%5Bgolf%5D=&search%5Bkitchenette%5D=&search%5Boceanview%5D=&search%5Bminiclub%5D=&search%5Bspa%5D=&search%5Bwedding%5D=&search%5Badultonly%5D=&search%5Bnoextrasingle%5D=&search%5Bvilla%5D=&s
from utils.scala_functions import find_matching_patterns
from pyspark.sql import functions as F
regexes = regex.agg(F.collect_list(F.col("pattern"))).collect()[0][0]
regexes = sc.broadcast(regexes)
articles = articles \
.withColumn("patterns", find_matching_patterns(F.col("text"), regexes.value)
.withColumn("patterns", F.when(F.col("patterns").isNull(), F.array(F.lit(None))).otherwise(F.col("patterns"))) \
.withColumn("pattern", F.explode(F.col("patterns")))
def findMatchingPatterns(regexes: ArrayList[String]): UserDefinedFunction = {
udf((value: String) => {
for {
text <- Option(value)
matches = regexes.asScala.filter(r => Pattern.matches(r, text))
if matches.nonEmpty
} yield matches
}, ArrayType(StringType))
}
wiki.join(regex, expr("text rlike pattern") how='left_outer')
@marcolivierarsenault
marcolivierarsenault / lossless_triplet_loss.py
Created February 14, 2018 19:21
Lossless triplet loss
def lossless_triplet_loss(y_true, y_pred, N = 3, beta=N, epsilon=1e-8):
"""
Implementation of the triplet loss function
Arguments:
y_true -- true labels, required when you define a loss in Keras, you don't need it in this function.
y_pred -- python list containing three objects:
anchor -- the encodings for the anchor data
positive -- the encodings for the positive data (similar to anchor)
negative -- the encodings for the negative data (different from anchor)
def triplet_loss(y_true, y_pred, alpha = 0.4):
"""
Implementation of the triplet loss function
Arguments:
y_true -- true labels, required when you define a loss in Keras, you don't need it in this function.
y_pred -- python list containing three objects:
anchor -- the encodings for the anchor data
positive -- the encodings for the positive data (similar to anchor)
negative -- the encodings for the negative data (different from anchor)
@marcolivierarsenault
marcolivierarsenault / Alt Coin Scraper
Created January 15, 2018 17:56
lamda function to get all the lambda function and store them in a database
import json
import decimal
import urllib.request
import boto3
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('AltCoinHistory')
def lambda_handler(event, context):
# change the prefix from 'C-b' to 'C-a'
# (remap capslock to CTRL for easy access)
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# start with window 1 (instead of 0)
set -g base-index 1
# start with pane 1