Skip to content

Instantly share code, notes, and snippets.

View Aaronphy's full-sized avatar
🏀
Focusing

Aaronphy Aaronphy

🏀
Focusing
View GitHub Profile
@robmathers
robmathers / groupBy.js
Created October 25, 2018 23:18
A more readable and annotated version of the Javascript groupBy from Ceasar Bautista (https://stackoverflow.com/a/34890276/1376063)
var groupBy = function(data, key) { // `data` is an array of objects, `key` is the key (or property accessor) to group by
// reduce runs this anonymous function on each element of `data` (the `item` parameter,
// returning the `storage` parameter at the end
return data.reduce(function(storage, item) {
// get the first instance of the key by which we're grouping
var group = item[key];
// set `storage` for this instance of group to the outer scope (if not empty) or initialize it
storage[group] = storage[group] || [];
@ilokhov
ilokhov / export-sync-bookmarks.js
Last active February 26, 2024 04:32
Node.js script for exporting and synchronising bookmarks from Google Chrome
const fs = require("fs");
const path = require("path");
function newItem(name, url) {
return { name, url };
}
const bookmarkPath = path.join(
process.env.HOME,
"/Library/Application Support/Google/Chrome/Default/Bookmarks"
@brrd
brrd / electron-dynamic-include.js
Last active July 5, 2022 07:02
Electron: dynamic include JS and/or CSS from a dependency in renderer process
// Install 'module-name' as a dependency, then:
function init () {
return new Promise ((resolve, reject) => {
const injectScript = (src, callback) => {
const script = document.createElement('script');
document.head.appendChild(script);
script.onload = callback;
script.src = src;
};
@joelgriffith
joelgriffith / big-screenshot.js
Created February 23, 2018 00:07
Large Puppeteer Images
const puppeteer = require('puppeteer');
const merge = require('merge-img');
const pageUrl = ''; // REPLACE ME
const pageElement = '#svgcanvas'; // REPLACE ME
(async() => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(pageUrl);
@arvkmr
arvkmr / Photoshop Android Icons.jsx
Created December 1, 2017 21:17
Photoshop script to export icons for Android apps
// Updated version of script by Todd Linkner
// This script is for Photoshop CS6. It outputs Android icons of the
// xxxhdpi - ldpi from a source PSD at least 512px x 512px
/*
// BEGIN__HARVEST_EXCEPTION_ZSTRING
<javascriptresource>
<name>$$$/JavaScripts/OutputAndroidIcons/MenuAlt=Output Android Icons</name>
<category>mobile</category>
@omarmiatello
omarmiatello / EasyWS.kt
Last active May 6, 2024 12:08
First experiment with WebSocket and Kotlin Coroutine
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.launch
import okhttp3.*
import okio.ByteString
import kotlin.coroutines.experimental.suspendCoroutine
/**
* Created by omarmiatello on 17/06/17.
*/
@bitmingw
bitmingw / git_batch_resolver.py
Last active September 18, 2023 08:20
Batch script to resolve large git conflicts.
#!/usr/bin/env python3
"""
Author: Ming Wen (bitmingw@gmail.com)
When resolving conflicts on a merge or rebase, this script
automates `git add/rm` and `git checkout` with --ours or --theirs
for a large batch of changes.
Usage: `python3 git_batch_resolver.py` in your git repository.
@jesty
jesty / OtherActivity.java
Last active July 6, 2023 06:36
Share cookies between WebView and OkHttpClient 3 / Retrofit 2. In the example I did the login on a web page in a WebView component and then I used the cookie to invoke a service from an activity
//Setup the client
OkHttpClient client = new OkHttpClient.Builder()
.cookieJar(new CookieJar() {
@Override
public void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
}
@Override
@pgherveou
pgherveou / yield-to-async.js
Created October 5, 2016 16:12
convert co/yield to to async/await
// http://astexplorer.net/#/BICnPGGYdU/4
export default function ({types: t}) {
return {
visitor: {
FunctionDeclaration(path) {
if (path.node.generator) {
path.node.async = true
path.node.generator = false
}
@nosix
nosix / Capture.kt
Created September 18, 2016 08:40
Taking a snapshot of the screen for Android (SDK 21) in Kotlin 1.0.3
package xxx
import android.content.Context
import android.graphics.Bitmap
import android.graphics.PixelFormat
import android.hardware.display.DisplayManager
import android.hardware.display.VirtualDisplay
import android.media.ImageReader
import android.media.projection.MediaProjection
import android.util.Log