Skip to content

Instantly share code, notes, and snippets.

View ezirmusitua's full-sized avatar
🎯
Focusing

ezirmusitua ezirmusitua

🎯
Focusing
View GitHub Profile
@ezirmusitua
ezirmusitua / apply-and-use-letsencrypt-cert.sh
Last active January 9, 2019 06:34
[Use let's encrypt cert with certbot] renew let's encrypt cert using certbot via nginx webroot, #nginx #https #certbot #bash #deploy
# 1. preparation
## 1.1 create cert-webroot
sudo mkdir /opt/sites/cert-webroot
cd /opt/sites/cert-webroot
## 1.2 create demo page
sudo touch index.html
sudo echo "<!DOCTYPE html>\n<html lang="en">\n<head>\n<meta charset="UTF-8">\n<title>Demo Site</title>\n</head>\n<body>\n<h1>This is a demo site</h1>\n</body>\n</html>" > index.html
## 1.3 update nginx default config
cd /etc/nginx/sites-enabled
vim default
@ezirmusitua
ezirmusitua / nginx_static_site.conf
Created January 9, 2019 06:37
[Nginx static site config] use nginx to serve static site(use letsencrypt cert & mantain with certbot) #deploy #nginx
## sitename.com
server {
listen 80;
listen [::]:80;
# expires $expires;
server_name <site_name>;
location ^~ /.well-known/acme-challenge/ {
@ezirmusitua
ezirmusitua / nginx_proxy_pass.conf
Created January 9, 2019 06:41
[Nginx proxy pass config] use nginx proxy pass (use letsencrypt cert & mantain with certbot) #deploy #nginx
## demo site
server {
listen 80;
listen [::]:80;
server_name <site_name>;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
@ezirmusitua
ezirmusitua / nginx_wmp_verification.config
Created January 9, 2019 06:45
[Weixin mini-program api server verification nginx config] weixin mini program api server verification, #nginx #deploy #weixin
server {
listen 80;
listen [::]:80;
server_name <api_server_name>;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
@ezirmusitua
ezirmusitua / scroll-to-positon.js
Created January 14, 2019 04:09
[Inside element scroll to position] scroll to position inside element(scollable element) #javascript #html
const elem = document.querySelecor('#scollableElement');
// scroll to specific position
elem.scrollTop = 100px;
elem.scrollLeft = 200px;
// scroll to bottom/right
elem.scrollTop = elem.scrollHeight;
elem.scrollLeft = elem.scrollWidth;
@ezirmusitua
ezirmusitua / leancloud-realtime.sh
Last active January 17, 2019 15:18
[Leancloud realtime REST api] curl demo of using leancloud realtime REST API #leancloud #curl
# create conversation
curl -X POST \
-H "X-LC-Id: JeUOhVkPeBkCbfnRA3mWWe8j-gzGzoHsz" \
-H "X-LC-Key: Sln8zi7RaBvwIvE1ka6DYWf2" \
-H "Content-Type: application/json" \
-d '{"name":"My Private Room","m": ["BillGates", "SteveJobs"]}' \
https://jeuohvkp.api.lncld.net/1.2/rtm/conversations
# get conversation
@ezirmusitua
ezirmusitua / video-player.js
Last active January 17, 2019 15:19
[Local video server] Simplest node video player running in localhost #node #javascript #tools #video
const fs = require('fs');
const path = require('path');
const http = require('http');
function createServer(videoRepoPath) {
return http.createServer((req, res) => {
if (/video\/.*\/view/gi.test(req.url)) {
console.log(req.url, req.url.split('/'));
const [, , video] = req.url.split('/');
const ext = path.extname(video);
@ezirmusitua
ezirmusitua / .py
Last active January 17, 2019 15:20
[Morse encoding] codewar challenge: morse encoding #python #algorithm #challenge
def convert_complement_to_dec(str):
if str[0] == '1':
reversed_str = ''
for bit in str[1:]:
reversed_str += '1' if bit == '0' else '0'
return -1 * (int('0b' + reversed_str, 2) + 1)
return int('0b' + str, 2)
def convert_dec_to_complement(val):
val_bin = bin(val)
@ezirmusitua
ezirmusitua / largest-numeric-plaindrome.py
Last active January 17, 2019 15:20
[Find largest numeric plaindrome] codewar challenge: Largest Numberic Plain drome #algorithm #challenge #python
from operator import mul
from functools import reduce
from itertools import combinations
def all_combinations_from(arr, start=2):
result = list()
for i in range(start, len(arr) + 1):
for t in combinations(arr, i):
result.append(reduce(mul, t))
print('combinations result: ', result)
@ezirmusitua
ezirmusitua / image-viewer.js
Last active January 17, 2019 15:26
[Local image server] Simplest node image viewer with pagination in localhost #node #javascript #tools #image
// usage: node image-viewer <Gallery Root>
const fs = require('fs');
const path = require('path');
const http = require('http');
// yarn add global gm & apt install graphicmagic
let gm;
try {
const gm = require('gm');
catch (err) {
console.warn('gm not found, run `$npm install gm` in script directory to install');