Skip to content

Instantly share code, notes, and snippets.

@wowdyaln
wowdyaln / mySQL transaction.php
Last active September 11, 2018 07:42
code snippet for question
<?
// ... ...
$conn->autocommit(FALSE);
$conn->begin_transaction();
for ($i=0; $i < count($users); $i++){
$user = $users[$i];
$nickname = $nicknames[ mt_rand(0, count($nicknames)-1 )];
$password = password_hash('123', PASSWORD_DEFAULT);

#Node - File Paths

##File Paths Node has a path module which can be used to manipulate paths.

###Normalizing Paths Paths can be stored in different ways and it is neccessary to ensure that the path is standardized.

var path = require('path');
path.normalize('/foo/bar//baz/asdf/quux/..');
@wowdyaln
wowdyaln / dbUpdate_twd97_to_wgs84.js
Created July 4, 2018 09:51
TWD97 convert to WGS84 with MongoDB
// * set database.
db = db.getSiblingDB('local');
// * coordinate converter.
// https://kuro.tw/posts/2015/06/11/js-note-twd97-convert-to-longitude-and-latitude/
function twd97_to_wgs84(x, y) {
let pow = Math.pow, M_PI = Math.PI;
let sin = Math.sin, cos = Math.cos, tan = Math.tan;
let a = 6378137.0, b = 6356752.314245;
let lng0 = 121 * M_PI / 180, k0 = 0.9999, dx = 250000, dy = 0;
@wowdyaln
wowdyaln / 136_Single Number_1.js
Last active January 25, 2018 11:38
leetcode_136
// 給一個 array, 一個 ele ,
function onlyOne(arr, ele) {
var count = 0;
// 先一個 for loop,算出 arr 裏面有幾個 ele
for (var i = 0; i < arr.length; ++i) {
if (arr[i] == ele)
count++;
}
// 如果 ele 小於2個,那就是這個 ele 了
@wowdyaln
wowdyaln / bopomofo_hsu.custom.yaml
Last active January 9, 2018 08:21 — forked from lotem/squirrel.custom.yaml
【鼠鬚管】定製檔
patch:
switches:
- name: ascii_mode
reset: 1
states: [ 中文, 西文 ]
- name: full_shape
states: [ 半角, 全角 ]
@wowdyaln
wowdyaln / node
Created September 3, 2017 18:48
gitignore sample
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
@wowdyaln
wowdyaln / The Supermarket Queue.rb
Created July 6, 2017 02:51
[codewar] The Supermarket Queue
def queue_time(queue, cashier)
# 每個位置一起減去當中最小的值
def subtract_the_min(arr)
arr.map do |ele|
ele - arr.min
end
end
# 如果 at_a_certain_moment 裡面有0 -> 找到這個位置,塞入下一個顧客 ->直到每個位置都不是0

開源之道

Original transcript: http://allisonrandal.com/2012/04/15/open-source-enlightenment/

這幾年來,我慢慢覺得,我們參與開源社群,就像是在一條道路上並肩而行:這不僅讓我們成為更好的程式設計者,也讓我們通過與人合作,而成為更好的人。

您可以將它想成一條修行之道,讓身而為人的我們能夠不斷成長。接下來,我想談談我對開源世界的個人觀點,希望能與您分享。

首先,人是一切開源專案的核心。程式碼是很重要,但最核心的永遠是人。

@wowdyaln
wowdyaln / prime_Sundaram.rb
Created June 14, 2017 13:49
Sieve of Sundaram algorithm
##### Sieve of Sundaram algorithm
def prime_Sundaram(n)
n = n/2
a = []
a[n] = nil
t = (Math.sqrt(4+8*n)-2)/4
u = 0
r = []