Skip to content

Instantly share code, notes, and snippets.

@alegut
alegut / randstring.js
Created January 23, 2019 19:00
Random String JS
const rand = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
@alegut
alegut / auth.interceptors.ts
Last active January 15, 2019 18:23
Angular Intercaptors
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { Injectable } from '@angular/core';
import { AuthService } from '../auth/auth.service';
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
constructor(private authService: AuthService) {}
@alegut
alegut / factorial.js
Created January 13, 2019 17:37
Factorial riddle
function FirstFactorial(num) {
if (num === 0 || num === 1) {
return 1;
}
else {
var d = FirstFactorial(num - 1);
return num * d;
}
}
@alegut
alegut / sort,js
Created January 13, 2019 16:51
JS sorting numbers
const sorted = [4,78,6,-8].sort((a,b) => a - b);
console.log(sorted);
@alegut
alegut / register.php
Created December 26, 2018 09:25
Send JSON data from POST request to txt file
<?php
header("Content-Type: application/json; charset=UTF-8");
$data = json_decode(file_get_contents('php://input'), true);
//print_r($data);
foreach($data as $key => $value)
{
$str.=$key.":".$value."\n";
}
$file = 'people.txt';
// Open the file to get existing content
@alegut
alegut / index.js
Created October 30, 2018 17:33
React axios interceptors
import axios from 'axios';
axios.interceptors.request.use(request => {
console.log(request);
return request;
}, error => {
console.log(error);
return Promise.reject(error);
});
@alegut
alegut / DrawerToggle.css
Created October 28, 2018 18:30
Hamburger menu creation
.DrawerToggle {
width: 40px;
height: 100%;
display: flex;
flex-flow: column;
justify-content: space-around;
align-items: center;
padding: 10px 0;
box-sizing: border-box;
cursor: pointer;
@alegut
alegut / cryptoplugin.php
Created October 22, 2018 12:43
When WP theme dose not support shortcodes
add_filter('the_content', 'do_shortcode');
@alegut
alegut / index.html
Last active October 17, 2018 12:39
Pure JS slider
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Pure JS sider</title>
<link rel="stylesheet" href="pjs.css">
<script src="pjs.js"></script>
</head>
@alegut
alegut / readme.txt
Created October 13, 2018 07:57
Change rewrite rules apache2
$ sudo a2enmod rewrite
sudo nano /etc/apache2/apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
# service apache2 restart