Skip to content

Instantly share code, notes, and snippets.

View ayltai's full-sized avatar

Alan Tai ayltai

View GitHub Profile
@ayltai
ayltai / add-spacer.sh
Created June 8, 2020 08:47
macOS customization
defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="small-spacer-tile";}' && killall Dock
#!/bin/bash
cd "`dirname "$0"`"
echo 'Downloading VirtualBox - A hypervisor for x86 virtualization...'
wget https://download.virtualbox.org/virtualbox/6.1.4/VirtualBox-6.1.4-136177-OSX.dmg
echo 'Downloading VirtualBox Extension Pack - Extends the functionality of VirtualBox...'
wget https://download.virtualbox.org/virtualbox/6.1.4/Oracle_VM_VirtualBox_Extension_Pack-6.1.4.vbox-extpack
@ayltai
ayltai / forbes.greasemonkey.js
Created January 27, 2020 09:44
Forbes Anti AdBlocker
// ==UserScript==
// @name Forbes
// @namespace https://www.forbes.com/
// @description Remove anti ad-blockers on Forbes websites
// @version 1
// @include https://www.forbes.com/*
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
// ==/UserScript==
@ayltai
ayltai / vm_pageout.h
Created March 1, 2017 15:25
Extract of vm_pageout.h
#define VM_PAGER_DEFAULT 0x1 /* Use default pager. */
#define VM_PAGER_COMPRESSOR_NO_SWAP 0x2 /* In-core compressor only. */
#define VM_PAGER_COMPRESSOR_WITH_SWAP 0x4 /* In-core compressor + swap backend. */
#define VM_PAGER_FREEZER_DEFAULT 0x8 /* Freezer backed by default pager.*/
#define VM_PAGER_FREEZER_COMPRESSOR_NO_SWAP 0x10 /* Freezer backed by in-core compressor only i.e. frozen data remain in-core compressed.*/
#define VM_PAGER_FREEZER_COMPRESSOR_WITH_SWAP 0x20 /* Freezer backed by in-core compressor with swap support too.*/
DisplayMetrics metrics = new DisplayMetrics();
((WindowManager)adContainerView.getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(metrics);
ViewGroup.LayoutParams params = imageView.getLayoutParams();
params.width = metrics.widthPixels;
params.height = (int)(metrics.widthPixels / 1.91f + 0.5f);
imageView.setLayoutParams(params);
@Override
protected void prepare(@NonNull final NativeAppInstallAdView adView, @NonNull final NativeAppInstallAd nativeAd) {
final TextView adTitle = (TextView)adView.findViewById(R.id.ad_title);
final TextView adBody = (TextView)adView.findViewById(R.id.ad_body);
final ImageView adImage = (ImageView)adView.findViewById(R.id.ad_image);
final TextView adCallToAction = (TextView)adView.findViewById(R.id.ad_call_to_action);
adView.setHeadlineView(adTitle);
adView.setBodyView(adBody);
adView.setImageView(adImage);
dependencies {
compile('com.mopub:mopub-sdk-native-static:4.12.0@aar') { transitive = true }
compile 'com.facebook.android:audience-network-sdk:4.19.0'
compile 'com.flurry.android:analytics:6.8.0'
compile 'com.flurry.android:ads:6.8.0'
compile 'com.google.android.gms:play-services-ads:10.0.1'
// Other dependencies
}
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.ads.formats.NativeContentAdView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/admob_content_ad_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/view_native_ad" />
</com.google.android.gms.ads.formats.NativeContentAdView>
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.ads.formats.NativeAppInstallAdView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/admob_app_install_ad_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/view_native_ad" />
</com.google.android.gms.ads.formats.NativeAppInstallAdView>
@ayltai
ayltai / view_native_ad_container.xml
Created February 12, 2017 10:39
Empty view layout for native ads
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/native_ad_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"