Skip to content

Instantly share code, notes, and snippets.

Avatar

Ashik Nesin AshikNesin

View GitHub Profile
View browser-detect.js
function detect() {
if (typeof navigator !== 'undefined') {
return parseUserAgent(navigator.userAgent);
}
return getNodeVersion();
}
function detectOS(userAgentString) {
var rules = getOperatingSystemRules();
View Sidebar.js
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
import classNames from "classnames";
class Sidebar extends React.Component {
constructor(props) {
super(props);
this.state = {
showMenu: false
@AshikNesin
AshikNesin / letsencrypt_2017.md
Created Apr 8, 2018 — forked from cecilemuller/letsencrypt_2020.md
How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)
View letsencrypt_2017.md

How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

There are two main modes to run the Let's Encrypt client (called Certbot):

  • Standalone: replaces the webserver to respond to ACME challenges
  • Webroot: needs your webserver to serve challenges from a known folder.

Webroot is better because it doesn't need to replace Nginx (to bind to port 80).

In the following, we're setting up mydomain.com. HTML is served from /var/www/mydomain, and challenges are served from /var/www/letsencrypt.

@AshikNesin
AshikNesin / file-upload-local-url.js
Created Mar 21, 2018
Get URL of the selected file
View file-upload-local-url.js
$('#file-upload').change(function(e) {
const file = e.target.files[0]
console.log(URL.createObjectURL(file))
});
@AshikNesin
AshikNesin / base64-form-data.js
Last active Aug 26, 2020
Base64 image to multipart/form-data
View base64-form-data.js
const base64 = 'data:image/png;base65,....' // Place your base64 url here.
fetch(base64)
.then(res => res.blob())
.then(blob => {
const fd = new FormData();
const file = new File([blob], "filename.jpeg");
fd.append('image', file)
// Let's upload the file
// Don't set contentType manually → https://github.com/github/fetch/issues/505#issuecomment-293064470
@AshikNesin
AshikNesin / chrome-extension.js
Created Jul 19, 2017
Chrome Extension Close Current Page
View chrome-extension.js
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
chrome.tabs.remove(tabs[0].id);
});
@AshikNesin
AshikNesin / model-stop-video.js
Created Jun 16, 2017
Stop video if the model is closed
View model-stop-video.js
$(document).ready(function(){
$('.modal').each(function(){
var src = $(this).find('iframe').attr('src');
$(this).on('click', function(){
$(this).find('iframe').attr('src', '');
$(this).find('iframe').attr('src', src);
});
View validateEmail.js
// regex from http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
const EMAIL_REGEX = /^[-!#$%&'*+\/0-9=?A-Z^_a-z{|}~](\.?[-!#$%&'*+\/0-9=?A-Z^_a-z`{|}~])*@[a-zA-Z0-9](-?\.?[a-zA-Z0-9])*\.[a-zA-Z](-?[a-zA-Z0-9])+$/;
const validateEmail = email => {
return email
&& email.length < 255
&& EMAIL_REGEX.test(email);
};
export default validateEmail;
@AshikNesin
AshikNesin / async-await-playground.js
Created May 4, 2017
[Playground] Asynchronous JavaScript with async/await course
View async-await-playground.js
// https://egghead.io/courses/asynchronous-javascript-with-async-await
const fetch = require('node-fetch')
const fetchGitHubUser = async (handle) => {
const url = `https://api.github.com/users/${handle}`
const response = await fetch(url)
const body = await response.json()
if (response.status !== 200){
throw Error(body.message)
You can’t perform that action at this time.