Skip to content

Instantly share code, notes, and snippets.

@crackcatcher
crackcatcher / Makefile
Created October 30, 2024 04:17 — forked from colejhudson/Makefile
A base Makefile for compiling swift targeted for iOS without using XCode
# Adapted from http://vojtastavik.com/2018/10/15/building-ios-app-without-xcode/
SYS_BASE := /usr/local
SYS_LIB := $(SYS_BASE)/lib
SYS_INCLUDE := $(SYS_BASE)/include
ORGANIZATION := # Organization Name
NAME := # App Name
BUNDLE := $(NAME).app
@crackcatcher
crackcatcher / gist:71e01854324506840453be739deab9f5
Created February 2, 2023 13:31 — forked from donjaime/gist:5078567
PostMessage into a dynamically created iframe.
var frame = document.createElement("iframe");
frame.src="https://<the mothership's domain>/inner.html";
frame.onload = function() {
// If this is a Chrome content script, contentWindow is offlimits.
frame.contentWindow.postMessage("A Message!", "https://<the mothership's domain>");
}
document.body.appendChild(frame);
@crackcatcher
crackcatcher / promise.js
Created July 18, 2019 01:22 — forked from wavded/promise.js
Promise A+ Implementation
"use strict"
var Promise = function () {
this.state = 'pending'
this.thenables = []
}
Promise.prototype.resolve = function (value) {
if (this.state != 'pending') return
this.state = 'fulfilled'
@crackcatcher
crackcatcher / YourApplicationClass.java
Created March 8, 2019 03:20 — forked from Ray33/YourApplicationClass.java
An Asynchronous method to get user google advertising id.
//callback for user id:
//Either takes the user's advertiserId or creates a unique ID, if
AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
try {
AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(YourApplicationClass.this);
if (!adInfo.isLimitAdTrackingEnabled()) {//if user hasn't opt-out
return adInfo.getId();
}else{
@crackcatcher
crackcatcher / UserCountryUtil.java
Created March 8, 2019 03:19 — forked from Ray33/UserCountryUtil.java
Get user country by network
/**
* Get ISO 3166-1 alpha-2 country code for this device (or null if not available)
* @param context Context reference to get the TelephonyManager instance from
* @return country code or null
*/
public String getUserCountry(Context context) {
try {
final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final String simCountry = tm.getSimCountryIso();
if (simCountry != null && simCountry.length() == 2) { // SIM country code is available