Skip to content

Instantly share code, notes, and snippets.

View boostup's full-sized avatar
💭
👍

Fred B. boostup

💭
👍
View GitHub Profile
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch App",
"type": "node",
"request": "launch",
@boostup
boostup / settings.json
Created December 11, 2017 13:55
VSCode: Hiding files from the project files explorer. To be placed inside [root_directory]/.vscode
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/node_modules": true
}
}
@boostup
boostup / tag-old-commit.sh
Created December 11, 2017 15:42
GIT: Tag a past commit
# Set the HEAD to the old commit that we want to tag
git checkout 9fceb02
# temporarily set the date to the date of the HEAD commit, and add the tag
GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" \
git tag -a v1.2 -m"v1.2"
# set HEAD back to whatever you want it to be
git checkout master
@boostup
boostup / server.js
Last active December 13, 2017 09:13
node.js: how to pipe a output from child process into a webpage
/**
* Credits to:
* https://aaronaddleman.com/articles/how-to-pipe-a-output-from-child-process-into-a-webpage/
*/
// how to pipe a output from child process into a webpage
// start with importing an http server
var http = require('http');
// import the spawn function
var spawn = require('child_process').spawn;
@boostup
boostup / server.js
Last active July 24, 2020 10:43 — forked from RichFromGalvanize/gist:5873044
node.js: an image piping example using express and request
var request = require('request');
var express = require('express');
var app = express();
app.get('/goofy', function(req, res) {
request('http://images1.wikia.nocookie.net/__cb20120715102950/disney/images/a/a5/Disneygoofy2012.jpeg').pipe(res);
});
app.get('/loop', function(req, res) {
res.render('mypage');
@boostup
boostup / createFile.js
Last active December 13, 2017 14:03
create huge file. then create readable stream with file and flush out line by line to the console
const fs = require('fs');
const file = fs.createWriteStream('./big.file');
for(let i=0; i<= 500000; i++) {
file.write('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n');
}
file.end();
@boostup
boostup / readJsonFileAsync.js
Created March 30, 2018 08:13 — forked from wuchengwei/readJsonFileAsync.js
NodeJS - Read in a json file asynchronously
/*
* @param {String} filepath
* @param {function} callback function(err, data){}
*/
function readJsonFileAsync(filepath, callback) {
var fs = require('fs');
fs.readFile(filepath, 'utf-8', function(err, data) {
if (err) { callback(err, null); }
else {
result = JSON.parse(data);
@boostup
boostup / stamp-it.js
Last active June 5, 2018 23:05
This code is some quick and dirty one! This is not meant for production code. It is meant to run as bookmarklet on chrome latest. On the browser, the page opened must be a playing video at https://www.youtube.com. Then, clicking on the bookmarklet containing this code will allow to log into the browser console the video metadata, time elapsed al…
function minTohhmmss(totalSeconds){
var hours = Math.floor(totalSeconds / 3600);
totalSeconds %= 3600;
var minutes = Math.floor(totalSeconds / 60);
var seconds = Math.floor(totalSeconds % 60);
var ret = "";
hours ? ret = hours + "h" : "";
minutes ? ret += minutes + "m": "";
const formatForHtml = (textString) => {
return textString.split("\n").map(function (line, idx) {
return (
<div key={idx}>
{`${line}`}
<br />
</div>
);
});
};
const responseGoogleStatus = (responseType) => {
return (response) => {
console.log(responseType, response);
if (responseType == "Success") {
loggedIn = true;
token = response.accessToken;
}
if (responseType == "Failed") {
throw new Exception("Some error from Google API response", response);