Skip to content

Instantly share code, notes, and snippets.

View germanattanasio's full-sized avatar
🇦🇷
Learning

German Attanasio germanattanasio

🇦🇷
Learning
View GitHub Profile
@germanattanasio
germanattanasio / snippet.html
Created November 17, 2023 16:54
Check if user agent is a bot
<script>
const checkIfUserAgentIsBot = (userAgent) => {
const robots = new RegExp(([
/bot/,/spider/,/crawl/, // GENERAL TERMS
/APIs-Google/,/AdsBot/,/Googlebot/, // GOOGLE ROBOTS
/mediapartners/,/Google Favicon/,
/FeedFetcher/,/Google-Read-Aloud/,
/DuplexWeb-Google/,/googleweblight/,
/bing/,/yandex/,/baidu/,/duckduck/,/yahoo/, // OTHER ENGINES
/ecosia/,/ia_archiver/,
@germanattanasio
germanattanasio / stt.sh
Last active November 22, 2021 17:21
curl commands to use the Speech to Text service
#!/bin/sh
# This script clears the terminal, call the IBM Watson Speech to Text service.
USERNAME="<SERVICE_USERNAME>"
PASSWORD="<SERVICE_PASSWORD>"
SESSION_ID="<SESSION_ID>" # you will get this after running (1)
# 1. Create a session:
curl -X POST -b cookies.txt -c cookies.txt -u $USERNAME:$PASSWORD -d "{}" "https://stream.watsonplatform.net/speech-to-text/api/v1/sessions"
# This returns you a session URL. Note that the client needs to support cookies for sessions to work.
@germanattanasio
germanattanasio / blockchain.py
Created December 15, 2020 21:18
Mining the nonce for a take home exam at NYU Stern
import hashlib
import time
import re
from datetime import date
# Block information
block = 1
data = 'German gets a PD'
prevHash = '0000000000000000000000000000000000000000000000000000000000000000'
@germanattanasio
germanattanasio / latin-1-regexp.js
Last active November 4, 2020 13:36
Basic Latin-1 Letter Regular Expression (JavaScript)
var regexp = /^[A-z\u00C0-\u00ff\s'\.,-\/#!$%\^&\*;:{}=\-_`~()]+$/,
ascii = ' hello !@#$%^&*())_+=',
latin = 'Panamá, ratón, cortés, árbol, azúcar, ángel',
chinese = ' 你 好 ';
console.log(regexp.test(ascii)); // true
console.log(regexp.test(latin)); // true
console.log(regexp.test(chinese)); // false
@germanattanasio
germanattanasio / README.md
Last active November 27, 2019 16:45
Create a Watson Assistant service instance programmatically

Creating a service instance programmatically.

1. Create a platform apikey

In order to create/delete service instances programmatically a platform apikey needs to be used.

@germanattanasio
germanattanasio / manifest.yml
Created July 7, 2017 12:11
Deploy a Node.js Cloud-Foundry application to IBM Bluemix from Travis
---
applications:
- name: my-app-name
buildpack: sdk-for-nodejs
memory: 512M
timeout: 120 # The maximum amount of time in seconds that is used to start the application. The default value is 60 seconds.
instances: 1
command: npm start
path: .
@germanattanasio
germanattanasio / visual-recognition-fetch.js
Last active March 27, 2018 16:30
Call classify for Visual Recognition v3 using the fetch API
// When testing in node you will have to install `form-data` and `node-fetch`. You don't need them in React Native.
// const fetch = require('node-fetch');
// const FormData = require('form-data');
const VISUAL_RECOGNITION_API = 'https://gateway-a.watsonplatform.net/visual-recognition/api';
const CLASSIFY_ENDPOINT = '/v3/classify';
const apiKey = 'API_KEY_HERE'; // replace with a valid API Key
/**
* Classifies an image using the Visual Recognition service
@germanattanasio
germanattanasio / main.py
Created March 3, 2018 04:46
Sends messages to conversation using a csv file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function # Python 3 support
import sys
import json
import datetime
import re
import csv
@germanattanasio
germanattanasio / Example.java
Last active March 31, 2017 03:41
IBM JDK and SSL context
// Copy this class in the java-sdk/text-to-speech/src/main/java/com/ibm/watson/developer_cloud/text_to_speech/v1/ folder
package com.ibm.watson.developer_cloud.text_to_speech.v1;
import java.util.List;
import com.ibm.watson.developer_cloud.text_to_speech.v1.model.Voice;
public class Example {
public static void main(String[] args) {
@germanattanasio
germanattanasio / app.js
Created August 1, 2015 03:42
Using Speech to Text with and shows interim results
'use strict';
// replace username and password with speech to text credentials
// audio.wav can be found here: https://github.com/watson-developer-cloud/nodejs-wrapper/blob/master/test/resources/audio.wav?raw=true
var watson = require('watson-developer-cloud'),
fs = require('fs');
var speechToText = watson.speech_to_text({
password: '<username>',
username: '<password>',