Skip to content

Instantly share code, notes, and snippets.

View longnz's full-sized avatar
💭
Working Remotely

Long Nguyen longnz

💭
Working Remotely
View GitHub Profile
<?php
// force download of CSV
// simulate file handle w/ php://output, direct to output (from http://www.php.net/manual/en/function.fputcsv.php#72428)
// (could alternately write to memory handle & read from stream, this seems more direct)
// headers from http://us3.php.net/manual/en/function.readfile.php
header('Content-Description: File Transfer');
header('Content-Type: application/csv');
header("Content-Disposition: attachment; filename=FILENAME.csv");
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
@longnz
longnz / .htaccess
Created February 28, 2019 12:54 — forked from morcegon/.htaccess
.htaccess optimized for laravel
# Apache configuration file
# httpd.apache.org/docs/2.2/mod/quickreference.html
# Note .htaccess files are an overhead, this logic should be in your Apache
# config if possible: httpd.apache.org/docs/2.2/howto/htaccess.html
# Techniques in here adapted from all over, including:
# Kroc Camen: camendesign.com/.htaccess
# perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/
# Sample .htaccess file of CMS MODx: modxcms.com
@longnz
longnz / docker-cleanup-resources.md
Created February 14, 2019 18:44 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

Strings

String.prototype.*

None of the string methods modify this – they always return fresh strings.

  • charAt(pos: number): string ES1

    Returns the character at index pos, as a string (JavaScript does not have a datatype for characters). str[i] is equivalent to str.charAt(i) and more concise (caveat: may not work on old engines).

@longnz
longnz / poorMansConvert.py
Created May 16, 2018 14:08 — forked from 9b/poorMansConvert.py
Uses the Google Drive API to upload a file, convert it to a file format, download it locally and delete it from Drive.
#!/usr/bin/python
def poorMansConvert(di, inPath, outType, outPath):
from apiclient.http import MediaFileUpload
valid_output = [
'text/html','text/plain','application/rtf','application/vnd.oasis.opendocument.text',\
'application/pdf','application/vnd.openxmlformats-officedocument.wordprocessingml.document',\
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/x-vnd.oasis.opendocument.spreadsheet',\
'image/jpeg','image/png','image/svg+xml','application/vnd.openxmlformats-officedocument.presentationml.presentation'
@longnz
longnz / gist:03e02688523549799be4023f49ecb03c
Created September 16, 2016 15:51 — forked from vestman/gist:5d9ce0c51869b33a8f51
Magento - Copy/duplicate Categories
<?php
if(!is_numeric($_GET['id']))die('Please specify a category ID');
$catId = $_GET['id'];
$xml = simplexml_load_file('app/etc/local.xml');
$host = $xml->global->resources->default_setup->connection->host;
$username = $xml->global->resources->default_setup->connection->username;
$password = $xml->global->resources->default_setup->connection->password;
@longnz
longnz / keybase.md
Last active December 13, 2023 13:40

Keybase proof

I hereby claim:

  • I am longnz on github.
  • I am gialac (https://keybase.io/gialac) on keybase.
  • I have a public key ASASAS5tjNcEc4HX5ZhVzm-FdAjz1_ZdNbVTrBKFaLn1swo

To claim this, I am signing this object:

@longnz
longnz / boot2docker-use-nfs.sh
Created December 8, 2015 21:22 — forked from olalonde/boot2docker-use-nfs.sh
Script to mount /Users with nfs instead of vboxsf in boot2docker
#!/bin/bash
#
# This script will mount /Users in the boot2docker VM using NFS (instead of the
# default vboxsf). It's probably not a good idea to run it while there are
# Docker containers running in boot2docker.
#
# Usage: sudo ./boot2docker-use-nfs.sh
#
@longnz
longnz / docker-machine-use-nfs.sh
Created December 8, 2015 21:22 — forked from olalonde/docker-machine-use-nfs.sh
Use NFS instead of vboxsf in Docker Machine
#!/bin/bash
#
# This script will mount /Users in the boot2docker VM using NFS (instead of the
# default vboxsf). It's probably not a good idea to run it while there are
# Docker containers running in boot2docker.
#
# Usage: sudo ./boot2docker-use-nfs.sh
#