Skip to content

Instantly share code, notes, and snippets.

View newvertex's full-sized avatar
🌵

newvertex newvertex

🌵
View GitHub Profile
@newvertex
newvertex / main.js
Created September 15, 2016 13:52
Add LiveReload to current Document
// Replace with your current LiveReload url
var liveReloadUrl = 'http://localhost:35729/livereload.js';
function liveReload(url){
var liveReloadTag = document.createElement('script');
liveReloadTag.type = 'text/javascript';
liveReloadTag.src = url;
document.body.appendChild(liveReloadTag);
}
@newvertex
newvertex / gist:f7d9768304addccd066e09687f8558fc
Created September 15, 2016 14:14
Add Live Reload to all html with our Http-Server on this url : https://github.com/newvertex/SimpleHttpServer
var liveReloadUrl = "http://localhost:35729/livereload.js";
var liveReloadTag = '<script type="text/javascript" src="' + liveReloadUrl + '"></script>"';
if(!String.prototype.insertAt){
String.prototype.insertAt = function(index = 0, string = '') {
if(index>0)
return this.substring(0, index) + string + this.substring(index, this.length);
else
@newvertex
newvertex / KeyPressEvent.js
Created September 17, 2016 10:24
Example: Detect keypress event in Node.js console app
var readline = require('readline');
readline.emitKeypressEvents(process.stdin);
if (process.stdin.isTTY)
process.stdin.setRawMode(true);
process.stdin.on('keypress', (chunk, key) => {
if (key && key.name == 'q')
process.exit();
@newvertex
newvertex / DownloadFromUrl.js
Last active September 21, 2016 17:05
Example: Download file from a url in Node.Js
let http = require('http');
let fs = require('fs');
function downloadFile(fileUrl, outputFileName) {
process.stdout.write(`Downloading: ${fileUrl}\n`);
let output = fs.createWriteStream(outputFileName);
http.get(fileUrl, (res) => {
res.pipe(output);
@newvertex
newvertex / image-uploader.js
Created December 6, 2016 20:40
A simple image uploader module to upload from url to imgur
let imgur = require('imgur');
imgur.setAPIUrl('https://api.imgur.com/3/');
function uploadIt(file) {
return imgur.uploadUrl(file);
}
module.exports.uploadIt = uploadIt;
@newvertex
newvertex / imageUpload.js
Last active December 6, 2016 20:49
A simple example of using image-uploader.js to upload from url
let fileLink = 'http://.....' // a valid image file link
imageUploader.uploadIt(fileLink)
.then((jsonResult) => {
console.log(`Image link is:\n ${jsonResult.data.link}`);
}).catch((err) => {
console.log(`Error on uploading image:\n ${err.message}\ntry again later`);
});
@newvertex
newvertex / ImgurJs.js
Created March 8, 2017 10:01
Upload image file from browser to imgur
const API = 'https://api.imgur.com/3/upload';
const CLIENT_ID = `Client-ID xxxxxxxxxxxxxxx`; // Get client-id from imgur: https://api.imgur.com/oauth2/addclient
function upload(file) {
let data = new FormData();
data.append('image', file);
return fetch(
API,
{
@newvertex
newvertex / Percentage.html
Created February 5, 2019 18:01
یه تیکه کد ساده که توی صفحه html اجرا میشه و میشه باهاش حدود مبلغ اصلی که بهش تخفیف خورده و به مبلغ فعلی رسیده رو بدست آورد
<!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" />
<script>
function calculate() {
var run = document.getElementById('run');
run.disabled = true;
@newvertex
newvertex / .htaccess
Created November 5, 2019 19:51
simple config to use laravel subdomain route in shared host
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Force to use www just for main domain, not for any subdomain
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
@newvertex
newvertex / sdl_opengl.rs
Created August 3, 2021 14:12
Basic setup OpenGL with SDL2 in Rust lang
// Cargo.toml
// -----------------------
// [dependencies]
// gl = "0.14.0"
// [dependencies.sdl2]
// version = "0.34.5"
// features = ["bundled", "static-link"]
use std::thread;