This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sample from @citizen428 https://dev.to/citizen428/comment/6cmh | |
FROM golang:alpine as build | |
RUN apk add --no-cache ca-certificates | |
WORKDIR /build | |
ADD . . | |
RUN CGO_ENABLED=0 GOOS=linux \ | |
go build -ldflags '-extldflags "-static"' -o app | |
FROM scratch | |
COPY --from=build /etc/ssl/certs/ca-certificates.crt \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/ | |
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating | |
// requestAnimationFrame polyfill by Erik Möller | |
// fixes from Paul Irish and Tino Zijdel | |
(function() { | |
var lastTime = 0; | |
var vendors = ['ms', 'moz', 'webkit', 'o']; | |
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { | |
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from decimal import Decimal, ROUND_HALF_UP | |
# https://docs.python.org/3/library/functions.html#round | |
# https://support.office.com/en-us/f1/topic/csh?HelpId=xlmain11.chm60075&NS=MACEXCEL&Version=90&Lcid=1033&UiLcid=1033&EntryPoint=True | |
def round_fixed(value, digit): | |
value_str = str(value) | |
value_dec = Decimal(value_str) | |
exp_unit = Decimal('0.1') ** digit | |
mini_unit = Decimal('0.1') ** (digit + 1) | |
if value_dec % exp_unit == (5 * mini_unit): | |
value_dec += mini_unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Link { | |
constructor(data) { | |
this.next = null; | |
this.data = data; | |
} | |
} | |
class Stack { | |
constructor(data) { | |
this.top = new Link(); | |
data.forEach(this.push.bind(this)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def search(A): | |
nums = len(A) | |
max = [] | |
cur = [] | |
for i in range(nums): | |
max.append(len(A[i])) | |
cur.append(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Rx = require('rxjs/Rx'); | |
const request = require('request'); | |
//Convert node method to Rx observable | |
const requestGet$ = function(url) { | |
let requestGetObservable = Rx.Observable.bindNodeCallback(request); | |
return requestGetObservable(url) | |
.do(x => console.log('requestGet$ is called')) | |
.map(x => x[1]) | |
.map(x => JSON.parse(x)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function replaceMoneyInString(disclaimer, new_price) { | |
const moneyRegexp = /\d+((,|'|\s)\d{3})*(\.\d*)?/; | |
let matches = disclaimer.match(moneyRegexp); | |
if (matches.length) { | |
let old_price_string = matches[0]; | |
let splitter = old_price_string.replace(/\d/g, '').trim(); | |
if (splitter.length === 1) { | |
let new_price_string = new_price.toString().replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, '$1' + splitter); | |
return disclaimer.replace(old_price_string, new_price_string); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webpack = require('webpack'); | |
var path = require('path'); | |
var HtmlWebpackPlugin = require('html-webpack-plugin'); | |
module.exports = { | |
entry: { | |
bundle: './src/index.js', | |
vendor: [ | |
'faker', 'lodash', 'redux', | |
'react-redux', 'react-dom', 'react-input-range', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const numbers = [1, 2, 3]; | |
function double(num) { | |
let [firstNumber, ...restNumbers] = num; | |
if (firstNumber) { | |
return [2 * firstNumber, ...(double(restNumbers))]; | |
} else { | |
return []; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Mulit-byte Unserialize (http://stackoverflow.com/questions/2853454/php-unserialize-fails-with-non-encoded-characters) | |
* | |
* UTF-8 will screw up a serialized string | |
* | |
* @access private | |
* @param string | |
* @return string | |
*/ |
NewerOlder