Skip to content

Instantly share code, notes, and snippets.

@kolserdav
kolserdav / graph.js
Created April 22, 2019 03:53
Canvas graphic
window.onload = () => {graph()};
function graph(){
const canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');
ctx.lineWidth = 0.5;
const minX = 20;
const minY = 10;
const arrowWidth = 3;
const arrowLength = 5;
const path = require('path');
module.exports = {
entry: ["./js/module.js"],
mode: 'development',
output: {
path: path.resolve(__dirname + './../../public/dist'),
filename: 'bundle.js'
},
module: {
rules: [
@kolserdav
kolserdav / init.d_service
Last active March 29, 2019 08:17
init.d script for node.js for debian
#! /bin/sh
# ------------------------------------------------------------------------------
# SOME INFOS : fairly standard (debian) init script.
# Note that node doesn't create a PID file (hence --make-pidfile)
# has to be run in the background (hence --background)
# and NOT as root (hence --chuid)
#
# MORE INFOS : INIT SCRIPT http://www.debian.org/doc/debian-policy/ch-opersys.html#s-sysvinit
# INIT-INFO RULES http://wiki.debian.org/LSBInitScripts
# INSTALL/REMOVE http://www.debian-administration.org/articles/28
const http = require('http')
const port = 3000
const requestHandler = (request, response) => {
console.log(request.url)
response.end('Hello Node.js Server!')
}
const server = http.createServer(requestHandler)
server.listen(port, (err) => {
if (err) {
return console.log('something bad happened', err)
if (status === 'success') {
//page.render("just loaded.jpg");
setTimeout(function(){
page.render("screenshots/web.jpg");
var num = evaluate(tag);
console.log(num);
phantom.exit();
}, 2500);
}
else {
@kolserdav
kolserdav / angular.component.ts
Created October 10, 2018 01:14
Add a tag script to Angular component.
import { Renderer2, Inject } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
export class AngularComponent{
constructor(private _renderer2: Renderer2, @Inject(DOCUMENT) private _document) {
}
ngOnInit(){
let s = this._renderer2.createElement('script');
s.type = `text/javascript`;
s.text = 'document.addEventListener("DOMContentLoaded", ()=>{\n' +
@kolserdav
kolserdav / include-materialize-to-angular
Created October 8, 2018 22:50
Add this to ./angular.json
"styles": [
"src/styles.css",
"./node_modules/materialize-css/dist/css/materialize.css"
],
"scripts": [
"./node_modules/jquery/dist/jquery.js",
"./node_modules/hammerjs/hammer.js",
"./node_modules/materialize-css/dist/js/materialize.js"
]
@kolserdav
kolserdav / index.js
Created September 6, 2018 12:31
NodeJs server
//Lambda Function Code
exports.handler = (event, context, callback)=>{
callback(null, JSON.stringify(event.result));
};
@kolserdav
kolserdav / setcookie.js
Created April 7, 2018 03:11
Create cookie with javascript
function setCookie(name, cookie, time){
let date = new Date(new Date().getTime() + time);
let nameCookie = name+"=";
document.cookie = nameCookie+cookie+"; "+"expires="+ date.toUTCString();
}
@kolserdav
kolserdav / base.html
Last active April 7, 2018 02:40
Rel import html file across javascript
<!doctype html>
<html>
<head>
<link rel="import" href="http://some.domain/patch.html">
</head>
<body>
<script src = "http://some.domain/js/main.js"></script>
</body>
</html>