Skip to content

Instantly share code, notes, and snippets.

@myleslee
myleslee / download-file.js
Created February 12, 2023 07:08 — forked from zynick/download-file.js
download file ('save as') using javascript xhr
// http://stackoverflow.com/a/23797348/1150427
xhr.open('POST', url, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
if (this.status === 200) {
var filename = "";
var disposition = xhr.getResponseHeader('Content-Disposition');
if (disposition && disposition.indexOf('attachment') !== -1) {
var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;

It seems that it does not matter what timezone is on the server as long as you have the time set right for the current timezone, know the timezone of the datetime columns that you store, and are aware of the issues with daylight savings time.

On the other hand if you have control of the timezones of the servers you work with then you can have everything set to UTC internally and never worry about timezones and DST.

Here are some notes I collected of how to work with timezones as a form of cheatsheet for myself and others which might influence what timezone the person will choose for his/her server and how he/she will store date and time.

MySQL Timezone Cheatsheet

Introduction

Object-Relational Mapping (ORM) allows you to work with objects and have them saved to the database automatically. It can greatly simplify create-read-update-delete (CRUD) operations and make your code more object-oriented. Under the hood ColdFusion uses the industry leading ORM framework called Hibernate.

Configuration

Application.cfc

Two settings are needed in the Application.cfc file to make an application use ORM: a datasource and ormEnabled set to true.

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.logging.Level;
@myleslee
myleslee / java.md
Last active June 27, 2016 13:09
java

Java 诞生至今已有二十余年,1991 年,Sun 公司的詹姆斯·高斯林(James Gosling)等人研究新技术,主要的目的是智能家电的控制与通讯。鉴于 C++ 的使用难度以及不同平台的可移植性问题,Sun 才没有继续使用 C++,而是决定开发一种新语言。一开始命名为 Oak(橡树),但最终由于商标已经被注册,所以改名为 Java,而 Java 的正式发布是在 1995 年的 SunWorld 大会上。随着上世纪 90 年代互联网的迅猛发展,Java 也得到了长足发展,时至今日,Java 已经是程序开发的中坚力量,最新的 tiobe 显示,Java 依然位列第一,尤其在Android、Hadoop大数据和云计算等领域,Java 的地位没有其他语言可以撼动。

Java 应用场景也有很多,Android app 开发、Java web 应用、虽然桌面软件并不是 Java 强项,但是依然有很多优秀的软件如 Eclipse、InetelliJ Idea 等均由 Java 开发,还有上面所说的大数据、云计算等领域。

与 C++ 的爱恨情仇

Java 的编程风格虽然与 C++ 十分接近,但却并不兼容,Java 是在 C++ 的基础上设计出来的,所以拥有 C++ 的一些特性,比如继承、多态等,但同时由于 C++ 在某些方面的问题,Java 在 C++ 的基础上又做了很多改进,比如 Java 舍弃了 C++ 中的指针,而是以引用的方式替换,虽然后续 Boost C++ 中添加了 smart_ptr,其中有因为 auto_ptr 的缺陷(例如不能共享权限、不能指向数组等)引入 shared_ptr 与 weak_ptr,而单独的 shared_ptr 也需要 weak_ptr 的帮助来解决循环引用的问题,仍然需要开发者去关注引用计数,对开发者而言并不是很友好,而 Java 以引用的方式取而代之。即使专家级的程序员编写的 C++ 程序仍然不能完全避免由内存释放而引起的内存泄露,而且也是相当繁琐的一项工作,所以 Java 引入 GC,让这些繁琐而又容易出错的事情交由计算机负责。 而同时为了避免多重继承而导致的一些数据安全问题(比如菱形继承) Java 也弃用了多继承,取而代之的是用接口的方式。当然,单继承语言也有其弊端,这里不过多阐述。

说到跨平台,就不得不说 JVM(Java Virtual Machi

@myleslee
myleslee / .bash_profile
Created January 9, 2016 02:17 — forked from natelandau/.bash_profile
Mac OSX Bash Profile
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management
@myleslee
myleslee / osx_uninstall_mysql_install_mariadb_homebrew.md
Created January 9, 2016 01:53 — forked from brandonsimpson/osx_uninstall_mysql_install_mariadb_homebrew.md
OSX How To: Uninstall native MySQL and install MariaDB via Homebrew

OSX How To: Uninstall native MySQL and install MariaDB via Homebrew

This is a short overview on how to completely remove any old mysql server installs in OSX and upgrade to MariaDB without conflicts. Things can get a bit weird when you have various old installs of MySQL server floating around, and utilizing homebrew to install and upgrade MariaDB as a drop in replacement for MySQL has worked well, especially if you're used to managing MySQL installs via yum in linux.

First: Backup Your Data!

Backup all of your current databases with mysqldump

This isn't a tutorial on backups, and there are many ways to do it. You should know how to backup your data anyway. For this example, we'll do a full backup of our InnoDB databases.

@myleslee
myleslee / Hello PHP.md
Last active October 30, 2015 10:29 — forked from juvenn/Hello PHP.md

LeanCloud 家族添新丁,PHP 的小伙伴们等急了吗?

PHP 作为 Web 平台部署最为广泛的语言之一,其易于部署的特性赢得了广大开发者的支持。今天我们非常高兴地发布了基于 PHP 的 LeanCloud SDK - 0.1.0 版,欢迎 PHP 粉丝们来测试使用,并为我们提供意见和建议。

0.1.0 版本主要支持数据存储,包括用户的管理、对象的存储查询,以及文件存储,可以在 PHP 5.3 及以上的运行环境中使用。部署到云引擎的功能将会在后续版本中支持。

云引擎是个啥?简单说它是部署在 LeanCloud 云端的后端,即云版的后端,它自然也沿袭了传统后端的优势。比如一个应用有 iOS、Android、Windows Phone 和 Web 四个版本,如果我们把程序逻辑放前端,那就要维护四套语言版本,四种接口不但难于统一,而且一旦程序逻辑有更改,各前端都得重新部署上线,这些问题严重加大了开发者的工作量和负担。现在逻辑在云端用 PHP 写一份,各前端发来请求,PHP 处理后返回数据;后端逻辑修改后,只要一键热部署即生效,惬意极啦!

谁说 PHP 要没落,谁说 JavaScript 要一统天下……PHP 的小伙伴们,这里有你们的新天地。