Skip to content

Instantly share code, notes, and snippets.

View ball6847's full-sized avatar
🎯
Focusing

Porawit Poboonma ball6847

🎯
Focusing
  • 7 Peaks Software Co., Ltd.
  • Bangkok, Thailand
View GitHub Profile
@ball6847
ball6847 / ascii-spinner.component.ts
Last active May 23, 2018 08:15
Angular 6 ... Very Simple Ascii Spinner
import { ChangeDetectionStrategy, Component, Input, OnInit, SimpleChanges } from '@angular/core';
import { Observable, from, of } from 'rxjs';
import { concatAll, delay, map, repeat } from 'rxjs/operators';
export type AsciiSpinnerPreset =
| 'dot'
| 'dot_cycle'
| 'z_arrow'
| 'z_b'
| 'z_d'
mkdir ~/extensions
git clone -b ubuntu-18.04 --single-branch https://github.com/passingthru67/workspaces-to-dock.git --depth 1 ~/extensions/workspaces-to-dock
ln -sf ~/extensions/workspaces-to-dock/workspaces-to-dock/[email protected] $HOME/.local/share/gnome-shell/extensions/
killall -3 gnome-shell
@ball6847
ball6847 / app.effects.ts
Last active April 6, 2018 19:50
ngrx/effects - handle request one by one
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Actions, Effect } from '@ngrx/effects';
import { DataPersistence } from '@nrwl/nx';
import { from } from 'rxjs/observable/from';
import { bufferCount, concatAll, switchMap } from 'rxjs/operators';
import { AppState } from './app.interfaces';
@Injectable()
@ball6847
ball6847 / delayThreshold.ts
Last active April 2, 2018 18:57
rxjs operator, make the data not emit too fast
import { timer } from 'rxjs/observable/timer';
import { delayWhen } from 'rxjs/operators';
export const delayThreshold = (threshold: number, start = Date.now()) =>
delayWhen(() => {
const delay = threshold - (Date.now() - start);
return timer(delay > 0 ? delay : 0);
});
#!/usr/bin/env bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
gluster volume start public_upload force
gluster volume start uploads force
mkdir -p /var/www/{uploads,public/upload}
mount.glusterfs 127.0.0.1:/public_upload /var/www/public/upload
mount.glusterfs 127.0.0.1:/uploads /var/www/uploads
@ball6847
ball6847 / setup.sh
Last active February 3, 2018 20:59
setup go workspace separated from $GOROOT using direnv, make it work nicely with gvm
#!/bin/bash -e
# assuming you've already installed GO and direnv
# and your desired workspace is at $HOME/go-workspace
# first, create workspace skeleton and go to workspace
mkdir -p ~/workspace/{bin,src,pkg}
cd ~/workspace/
# create .envrc with predefined layout (direnv built-in layout)
@ball6847
ball6847 / publish.sh
Last active January 14, 2018 19:39
quick copy and publish
#!/bin/bash
rm -rf dist
mkdir dist
find ./ \( \
-name "*.js" -o -name "*.js.map" -o -name "*.d.ts" -o -name "*.metadata.json" -o -name "package.json" \
\) -not \( \
-path "./node_modules/*" -o -path "./dist/*" \
\) | xargs cp --parent -t ./dist
gh-pages -d dist -b npmjs
@ball6847
ball6847 / environment.ts
Last active November 1, 2017 03:47
Enabling hot module replacement for angular cli project
// environments/environment.ts
export const environment = {
production: false,
hmr: true
};
@ball6847
ball6847 / server.js
Created October 15, 2017 18:43
Chrome Headless SSR for Old School
const puppeteer = require('puppeteer')
const express = require('express')
const app = express()
// page with angularjs application
const url = 'http://ng-seo.sourcelab.xyz/'
app.get('/', async function (req, res) {
const browser = await puppeteer.launch()
const page = await browser.newPage()
@ball6847
ball6847 / angular-responsify.js
Last active October 6, 2017 10:13
make your angularjs component update on screen breakpoint changes until the scope is destroyed
function responsifyFactory($window, rx, screenSize) {
// observable singleton
const observable$ = rx.Observable.fromEvent($window, 'resize')
.map(() => screenSize.get())
.distinctUntilChanged()
return ($scope = null) => {
// you might need to interact with observable directly in controller
// simply return observable if service has been called with no arguments
if ($scope === null) {