Skip to content

Instantly share code, notes, and snippets.

View JhonatanHern's full-sized avatar
🎯
Focusing

Jhonatan JhonatanHern

🎯
Focusing
View GitHub Profile
@JhonatanHern
JhonatanHern / CSRFPrevent.js
Created June 21, 2018 19:57
Prevention of CSRF attacks. Module intended to be used with express.js
const url = require('url')
module.exports = (request,domainName) => {
console.log(request.headers)
if (request.headers.referer) {
const parsedURL = url.parse(request.headers.referer)
return parsedURL.hostname === domainName ||
parsedURL.hostname === '127.0.0.1' ||
parsedURL.hostname === 'localhost'
}
@JhonatanHern
JhonatanHern / proxy.js
Created September 13, 2018 15:03
lightweight proxy made in node.js to avoid cors issues when working with holochain and React.js. Became useless with the usage of the "proxy" option in the "dna.json" file. Preserved for educational purposes since it handles several important concepts for begginers.
const http = require('http'),
url = require('url')
const PORT = 3939
const allowedSources = [
'::1',
'localhost',
/^127\.0\.0\.\d\d?\d?$/
]
@JhonatanHern
JhonatanHern / stupid_movistar.py
Last active January 9, 2019 20:32
My current ISP (Movistar) has a really bad system that crashes the connection every 5 or 10 minutes, my solution is this python script that pings google and restarts the connection when the ping fails.
#!/usr/bin/python
import os
import time
def checkConnection ():
return os.system("ping -c 1 google.com") == 0
def connect():
os.system("nmcli con up 'Movistar Default'")
<script src="https://www.google.com/recaptcha/api.js?render=6LduhJcUAAAAAJ7L1bpfSKOIkzvnWOX4hPgNDNBO"></script>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('6LduhJcUAAAAAJ7L1bpfSKOIkzvnWOX4hPgNDNBO', {action: 'form_validation'}).then(function(token) {
document.getElementById('g-recaptcha-response').value = token;
});
});
</script>
<?php
function httpPost($url, $data){
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
const fs = require('fs'),
{ promisify } = require('util'),
express = require('express')
const asyncStat = promisify(fs.stat)
var router = express.Router()
router.use(function(req, res, next){next()})
import React from 'react'
const Slice = props => (
<div className={props.current===props.index?'active':null}>
<label onClick={props.activate} >{props.index + 1}</label>
<div>
<section>
{props.children}
<br/>
<div className="acordeon-buttons">
curl -s https://api.github.com/repos/holochain/holochain-rust/releases/latest \
| grep browser_download_url \
| grep linux-x64 \
| cut -d '"' -f 4 \
| wget -qi -
<pre>
<?php
$string = 'vrcec,wrcwercr,cref43e3d,c*&^U,efrwe';
echo $string;
echo "<br>";
$stuff = explode( ',' , $string );
print_r($stuff);
foreach ($stuff as $key => $value){
$cgars = str_split( $string );
@JhonatanHern
JhonatanHern / basicNN.R
Created July 2, 2019 21:42
Basic Neural Network
library(neuralnet)
# creating training data set
TKS= c(20,10,30,20,80,30,90,99,99,40,12,32)
CSS= c(90,20,40,50,50,80,90,99,99,10,20,30)
Placed=c(1 ,0 ,0 ,0 ,1 ,1 ,1 ,1 ,1 ,0 ,0 ,0)
df=data.frame(TKS,CSS,Placed)
nn=neuralnet(Placed~TKS+CSS,data=df, hidden=3, act.fct = "logistic", linear.output = FALSE)