Skip to content

Instantly share code, notes, and snippets.

Michael Chen yuhua-chen

View GitHub Profile
@DavidWells
DavidWells / aws-lambda-redirect.js
Created Jun 28, 2018
How to do a 301 redirect from an AWS lambda function
View aws-lambda-redirect.js
exports.handler = (event, context, callback) => {
const response = {
statusCode: 301,
headers: {
Location: 'https://google.com',
}
};
return callback(null, response);
}
@themanifold
themanifold / node-prune.sh
Last active May 8, 2020
Pruning useless node_modules with bash userland tools (find etc)
View node-prune.sh
#!/usr/bin/env bash
find node_modules \( -name '__tests__' -o \
-name 'test' -o \
-name 'tests' -o \
-name 'powered-test' -o \
-name 'docs' -o \
-name 'doc' -o \
-name '.idea' -o \
-name '.vscode' -o \
-name 'website' -o \
@hassanazimi
hassanazimi / .htaccess
Last active Jun 9, 2020
The Best .htaccess with browser caching and gzip
View .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
@alexlee002
alexlee002 / xcplugin_update.sh
Created Apr 11, 2015
Auto update Xcode plugins to support new version of Xcode
View xcplugin_update.sh
#!/bin/sh
PLUGINS_DIR="$HOME/Library/Application Support/Developer/Shared/Xcode/Plug-ins"
XCODE_INFO_PATH=$(xcode-select -p)
XCODE_INFO_PATH=$(dirname "$XCODE_INFO_PATH")/Info
DVTPlugInCompatibilityUUID=$(defaults read "$XCODE_INFO_PATH" DVTPlugInCompatibilityUUID)
for plugin in "$PLUGINS_DIR"/*.xcplugin; do
plugin_info_path="$plugin/Contents/Info"
if [[ -f "$plugin_info_path.plist" ]]; then
@sburlot
sburlot / xc_ramdisk.sh
Created Mar 8, 2014
Creates a ramdisk and start Xcode with the DerivedData stored in ramdisk. Also deletes the ramdisk and reset Xcode prefs.
View xc_ramdisk.sh
#!/bin/bash
# Creates a ramdisk and start Xcode with the DerivedData stored in ramdisk. Also deletes the ramdisk and reset Xcode prefs.
# xc_ramdisk.sh
# - creates a ramdisk, set Xcode DerivedData to this disk and start Xcode.
# - umount a ramdisk, set Xcode DerivedData to default
# Stephan Burlot, Coriolis Technologies, http://www.coriolis.ch
#
# based on Alex Shevchenko xcode_ramdisk.sh script (https://gist.github.com/skeeet/2367298)
# based on Diego Freniche xc-launch.sh script (https://github.com/dfreniche/xc-launch)
@zrxq
zrxq / gist:5363610
Last active Feb 3, 2016
CGRect inset with UIEdgeInsets
View gist:5363610
inline static CGRect CGRectEdgeInset(CGRect rect, UIEdgeInsets insets) {
return CGRectMake(CGRectGetMinX(rect)+insets.left, CGRectGetMinY(rect)+insets.top, CGRectGetWidth(rect)-insets.left-insets.right, CGRectGetHeight(rect)-insets.top-insets.bottom);
}
@wess
wess / UIButton+Addition.h
Created Jan 21, 2012
added setBackground for event to UIButton
View UIButton+Addition.h
#import <UIKit/UIKit.h>
@interface UIButton(WCButton)
@property (nonatomic, retain) NSMutableDictionary *backgrounds;
- (void) setBackgroundColor:(UIColor *)bgColor forState:(UIControlState)state;
@end
@incredimike
incredimike / variousCountryListFormats.js
Last active Aug 1, 2020
List of Countries in various Javascript data structures: Alphabetical country lists & Country data objects.
View variousCountryListFormats.js
// Lists of countries with ISO 3166 codes, presented in various formats.
// Last Updated: July 30, 2020
// If you're using PHP, I suggest checking out:
// https://github.com/thephpleague/iso3166
//
// JS developers can check out:
// https://www.npmjs.com/package/iso3166-2-db
// List of all countries in a simple list / array.
@bdunogier
bdunogier / curl_progress.php
Created Jun 16, 2011
PHP/cURL download progress monitoring
View curl_progress.php
<?php
file_put_contents( 'progress.txt', '' );
$targetFile = fopen( 'testfile.iso', 'w' );
$ch = curl_init( 'http://ftp.free.org/mirrors/releases.ubuntu-fr.org/11.04/ubuntu-11.04-desktop-i386-fr.iso' );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch, CURLOPT_NOPROGRESS, false );
curl_setopt( $ch, CURLOPT_PROGRESSFUNCTION, 'progressCallback' );
curl_setopt( $ch, CURLOPT_FILE, $targetFile );
You can’t perform that action at this time.