Skip to content

Instantly share code, notes, and snippets.

View adamloving's full-sized avatar
💭
10x Ninja Rockstar

Adam Loving adamloving

💭
10x Ninja Rockstar
View GitHub Profile
@adamloving
adamloving / ARTapToPlaceObject.cs
Created June 11, 2020 21:50
Place Object on surface in AR using Unity AR Foundation
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
// This script is inspired by:
// https://www.youtube.com/watch?v=x08UU-I8eZ8&list=PLw3UgsOGHn4loDyxHG75eJxSnxxVgB-Yb&index=5&t=0s
// video Getting Started With ARFoundation in Unity (ARKit, ARCore): https://www.youtube.com/watch?v=Ml2UakwRxjk&list=WL&index=4
[RequireComponent(typeof(ARRaycastManager))]
@adamloving
adamloving / typeahead-autocomplete.tsx
Created April 16, 2020 17:27
React typeahead autocomplete
import React from "react";
import { ActionMeta, ValueType } from "react-select";
import CreatableSelect from "react-select/creatable";
type CreatableMultiSelectProps = {
options: Set<string>; // available choices
values: Set<string>; // current selections
onChange: (values: Set<string>) => void;
};
@adamloving
adamloving / HelloPoi.java
Created March 25, 2015 21:21
Read PowerPoint ppt pptx using Apache Poi in java!
import java.io.*;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.POIXMLProperties.*;
import org.apache.poi.xslf.usermodel.*;
public class HelloPoi {
public static void main(String[] args) {
@adamloving
adamloving / gmail-bulk-delete.js
Last active December 12, 2019 07:42
Delete a bunch of emails (thousands) by tag from gmail
function batchDelete() {
var batchSize = 10; // Process up to 10 threads at once
for (i = 175; i > 0; i--) {
var threads = GmailApp.search('label:outbound older_than:' + i + 'd');
for (j = 0; j < threads.length; j += batchSize) {
GmailApp.moveThreadsToTrash(threads.slice(j, j+batchSize));
// Logger.log('finished move %d', j);
}
}
}
@adamloving
adamloving / base-neg-2.js
Created February 8, 2016 21:41
Toptal Codility Problem: Convert to-and-from base -2
'use strict';
function toDecimal(A) {
var sum = 0;
for (var i = 0; i < A.length; i++) {
sum += A[i] * Math.pow(-2, i);
}
return sum;
}
@adamloving
adamloving / truthiness.py
Created September 24, 2019 20:36
Python truth table and truthiness
import math
values = [
True, False, 1, 0, -1, "true", "false", "1", "0", "-1", "", None, math.inf, -math.inf, [], {}, [[]], [0], [1]
]
print("Truth Table")
print("-----------")
for value in values:
print(f"\t", end="")
@adamloving
adamloving / python_sucks.py
Last active September 23, 2019 17:05
Python is a very inelegant language. Here are some things I dislike.
# 1. Clunky lambda syntax
numbers = [1, 2, 3]
# don't do this...
doubled = list(map(lambda n: n * 2, numbers))
# There's no way to define the end of the block except that comma. What about wrapping lines?
# better for this case
doubled = [n * 2 for n in numbers]
@adamloving
adamloving / twitter-user-timeline.js
Created May 15, 2011 21:37
The simplest way to get a user's Twitter timeline using Javascript and jQuery
var url = "http://twitter.com/status/user_timeline/adamloving.json?count=10&callback=?";
$.getJSON( url, function( data ){ console.log(data) });
@adamloving
adamloving / .flake8.ini
Last active October 4, 2018 17:45
flake8 python linting configuration file
# on macOS, put this in ~/.config/flake8
[flake8]
max-line-length=88
ignore=
#E302 expected 2 blank lines, found 1
E302,
#E261 at least two spaces before inline comment
E261,
# E401 multiple imports on one line
E401,
@adamloving
adamloving / react-toggle.js
Created October 22, 2015 18:47
Bootstrap button group toggle react js example
var ProjectForm = React.createClass({
getInitialState: function() {
return { headerText: 'nothing' }
},
handleToggleChange: function(value) {
this.setState({ headerText: value.toUpperCase() })
},
render: function() {
return (
<form>