Skip to content

Instantly share code, notes, and snippets.

View trandaison's full-sized avatar

Son Tran trandaison

View GitHub Profile
@trandaison
trandaison / hexstring.js
Created September 5, 2022 10:31 — forked from tauzen/hexstring.js
Hex string to byte and other way round conversion functions.
function byteToHexString(uint8arr) {
if (!uint8arr) {
return '';
}
var hexStr = '';
for (var i = 0; i < uint8arr.length; i++) {
var hex = (uint8arr[i] & 0xff).toString(16);
hex = (hex.length === 1) ? '0' + hex : hex;
hexStr += hex;
@trandaison
trandaison / upload.js
Created October 7, 2018 12:40 — forked from virolea/upload.js
Tracking file upload progress using axios
upload(files) {
const config = {
onUploadProgress: function(progressEvent) {
var percentCompleted = Math.round( (progressEvent.loaded * 100) / progressEvent.total )
console.log(percentCompleted)
}
}
let data = new FormData()
data.append('file', files[0])
@trandaison
trandaison / nginx-options-request.conf
Created October 6, 2018 03:33 — forked from james2doyle/nginx-options-request.conf
A Nginx conf for handling OPTIONS request for functions like window.fetch
server {
# ...
# handle OPTIONS requests from window.fetch
if ($request_method = OPTIONS ) {
add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Methods "GET, OPTIONS";
add_header Access-Control-Allow-Headers "Authorization,content-type";
add_header Access-Control-Allow-Credentials "true";
@trandaison
trandaison / default.conf
Created August 30, 2018 13:54
NGiNX Configuration for Vue-Router in HTML5 Mode
server {
listen 80 default_server;
listen [::]:80 default_server;
root /your/root/path;
index index.html;
server_name you.server.com;
@trandaison
trandaison / geotool.js
Created June 15, 2018 04:06 — forked from Craftworks/geotool.js
測地系変換ライブラリ(WGS <=> TKY, degree <=> dms)
//------------------------------------------------------------------------------
// geotool.js - version 1.0.0
//
// Copyright (c) 2005 Craftworks Corp. All Right Reserved.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
@trandaison
trandaison / rspec_rails_cheetsheet.rb
Created September 12, 2017 07:25 — forked from redrick/rspec_rails_cheetsheet.rb
New expect syntax + new hash syntax and couple corrections
#Model
expect(@user).to have(1).error_on(:username) # Checks whether there is an error in username
expect(@user.errors[:username]).to include("can't be blank") # check for the error message
#Rendering
expect(response).to render_template(:index)
#Redirecting
expect(response).to redirect_to(movies_path)
@trandaison
trandaison / rspec_rails_cheetsheet.rb
Created September 12, 2017 07:25 — forked from them0nk/rspec_rails_cheetsheet.rb
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
<html>
<head>
<title>Google Maps Multiple Markers</title>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
</head>
<body>
<div id="map" style="height: 400px; width: 500px;">
</div>
<script type="text/javascript">
@trandaison
trandaison / after.sh
Created August 30, 2016 16:15 — forked from cluppi/after.sh
Turning SSL on for Homestead
#!/bin/sh
# Config for SSL.
echo "--- Making SSL Directory ---"
mkdir /etc/nginx/ssl
echo "--- Copying $i SSL crt and key ---"
openssl req -nodes -new -x509 -keyout /etc/nginx/ssl/server.key -out /etc/nginx/ssl/server.crt -subj "/C=US/ST=NY/L=NYC/O=Dis/CN=www.example.com"
echo "--- Turning SSL on in nginx.conf. ---"