Skip to content

Instantly share code, notes, and snippets.

View anacampesan's full-sized avatar
🏡
WFH

Ana Campesan anacampesan

🏡
WFH
View GitHub Profile
@anacampesan
anacampesan / copyToClipboard.html
Last active May 20, 2021 10:41
Copy to clipboard without input
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="secretInfo" style="display: none;">secret info</div>
<button type="button" id="btnCopy">Copy hidden info</button>
@anacampesan
anacampesan / add_constraint_mytable.php
Last active October 5, 2017 13:34
Add unique - Migration
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddConstraintMyTable extends Migration
{
/**
* Run the migrations.
*
@anacampesan
anacampesan / hostname.js
Last active August 11, 2017 13:58
Builtin hostname feature in JS
$(document).ready(function() {
$linkField = $('[name="form-link"]');
$sourceField = $('[name="form-source"]');
$linkField.keypress(function() {
$tempA = document.createElement('a');
$tempA.href = $linkField.val();
$sourceField.val($tempA.hostname);
$tempA.remove();
});
});
<script>
document.addEventListener('DOMContentLoaded', function() {
var notificationBtn = document.getElementById('notificationBtn');
var notificationBox = document.getElementById('notificationBox');
document.body.addEventListener('click', function(ev) {
notificationBox.style.display = 'none';
});
notificationBtn.addEventListener('click', function(ev) {
@anacampesan
anacampesan / Print.js
Created September 12, 2017 16:41
Bind functions to events in React
import React from 'react';
export default class Print extends React.Component {
constructor() {
super()
this.printStuff = this.printStuff.bind(this);
}
printStuff() {
function getQueryParam(param) {
// returns the query parameters portion from the url and gets rid of the ? at position [0]
var query = window.location.search.substring(1);
var startPos = query.indexOf(param);
if (startPos == -1) {
return false;
}
query = query.substring(startPos);
// checks if the desired param is the last one in the query
# -*- coding: utf-8 -*-
import requests
from meya import Component
class WitRequest(Component):
def start(self):
API_KEY = 'XXX'
url = 'https://api.wit.ai/message'
headers = {'Authorization': 'Bearer ' + API_KEY}
name: root
states:
greetings:
component: meya.input_string
properties:
text: Hi, what can I help you with?
output: intent
wit_request:
component: wit_request
transitions:
@anacampesan
anacampesan / wit1.py
Last active November 8, 2017 17:02
Wit Free Text
import json
obj = json.loads('{"msg_id":"07kg0Z1uAQMmLN6lM","_text":"i want links to racing and horses","entities":{"links_category":[{"suggested":true,"confidence":0.97013993755778,"value":"racing","type":"value"},{"suggested":true,"confidence":0.94886424860786,"value":"horses","type":"value"}]}}')
entities = obj['entities']
intents = []
for key in entities:
aux = []
for entity in entities[key]:
@anacampesan
anacampesan / user.py
Created November 15, 2017 16:21
OOP in Python
class User:
role = 'user'
def __init__(self, name):
self.name = name
def get_name(self):
print(self.name)
@classmethod