Skip to content

Instantly share code, notes, and snippets.

View tstachl's full-sized avatar

Thomas Stachl tstachl

  • Pilina
  • Remote
View GitHub Profile
@tstachl
tstachl / enable_gpg.sh
Last active October 12, 2022 21:06
This bash script enables GPG, Yubikey and SSH on a nixos live cd for my public key.
#!/run/current-system/sw/bin/sh
nix-env -iA nixos.git nixos.gnupg nixos.pinentry-curses
gpg --receive-keys DE749C31D060A160
echo "$( \
gpg --list-keys \
| grep DE749C31D060A160 -A 1 \
| head -1 | tr -d '[:space:]' \
):6:" | gpg --import-ownertrust;
@tstachl
tstachl / Imap.php
Created November 9, 2010 17:21
Zend_Auth_Adapter to authenticate via IMAP
<?php
/**
* Stachl
*
* LICENSE
*
* This source file is subject to the CC-GNU GPL license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://creativecommons.org/licenses/GPL/2.0/
@tstachl
tstachl / api_content_type.rb
Created August 18, 2013 22:01
This is a simple Rack Middleware to set the request content type for specific routes. It checks if a content type is set and does not override the existing one. The options allow you to specify the request methods, path (with a string or a regular expression) and the content type to be set.
module Rack
class ApiContentType
def initialize(app, methods = [:post, :patch], path = /^\/api\/v2+/, content_type = 'application/json')
@app = app
@methods = (methods.is_a?(Array) ? methods : [methods]).map{ |item| item.to_s.upcase }
@path = path
@content_type = content_type
end
def call(env)
@tstachl
tstachl / mootools.cloneEventsDeep.js
Created October 7, 2010 02:09
Teach mootools to clone events of children too.
Native.implement([Element, Window, Document], {
cloneEventsDeep: function(from, type){
if (this.getChildren().length > 0) {
this.getChildren().each(function(item, index) {
item.cloneEventsDeep(from.getChildren()[index], type);
});
this.cloneEvents(from, type);
} else {
this.cloneEvents(from, type);
}
@tstachl
tstachl / getAnchorBalance.js
Created April 23, 2022 16:51
Google App Script to get Anchor Protocol Earn balance for a terra wallet address.
function getAnchorBalance(addr) {
const contract = 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu';
const aUstBalance = JSON.parse(JSON.parse(UrlFetchApp.fetch("https://mantle.terra.dev/?cw20--balance=" + contract, {
method: 'post',
headers: { 'Accept-Encoding': 'gzip, deflate, br', 'Content-Type': 'application/json', 'Accept': 'application/json' },
payload: JSON.stringify({
operationName: null,
variables: {},
query: `{\n ${contract}: WasmContractsContractAddressStore(ContractAddress: \"${contract}\", QueryMsg: \"{\\\"balance\\\":{\\\"address\\\":\\\"${addr}\\\"}}\") {\n Height\n Result\n __typename\n }\n}\n`
})
@tstachl
tstachl / create_customer.ps1
Created August 13, 2013 23:21
This is a PowerShell v2 script that performs a simple customer creation action on the desk.com API and outputs the status text. Either "created" if the customer has been created or "Unprocessable Entity" if a customer with the same email already exists.
function createCustomer($first_name, $last_name, $title, $background, $email) {
$subdomain = "your-site-subdomain"
$username = "your@username.com"
$password = "YoUrPaSsWoRd"
$body = @"
{
"first_name": "$first_name",
"last_name": "$last_name",
"title": "$title",
"background": "$background",
@tstachl
tstachl / tailscale.sh
Created November 27, 2021 18:37
Proper tailscale install on debian based distros.
#!/usr/bin/env bash
# Everything needs to be run as root
if [ $(id -u) -ne 0 ]; then
printf "Script must be run as root.\n"
exit 1
fi
OS=$(lsb_release -si)
VERSION=$(lsb_release -sc)
@tstachl
tstachl / multipass.js
Last active September 1, 2021 07:01
A multipass example written for Node.js.
var crypto = require('crypto')
// site name is your desk.com subdomain
, siteName = 'site_name'
// api key is generated here: https://your_subdomain.desk.com/admin/channels/support-center/auth_settings
, apiKey = 'multipass_token'
, data = JSON.stringify({
uid: '19238333',
expires: (new Date(Date.now() + 120000)).toISOString(),
customer_email: 'john@example.com',
@tstachl
tstachl / Gemfile
Created January 15, 2014 16:43
Export knowledge base articles from desk.com and zip them up for a salesforce.com import.
source 'https://rubygems.org'
ruby '2.0.0'
gem 'desk_api', '0.5.0'
gem 'rubyzip', '1.1.0'
gem 'open_uri_redirections', '0.1.4'
@tstachl
tstachl / authy_ssh.sh
Created February 21, 2018 00:02
Steps to install Authy SSH CLI.
# download the code from github
wget https://raw.githubusercontent.com/authy/authy-ssh/master/authy-ssh
# run the install
sudo bash authy-ssh install /usr/local/bin
# enable it
sudo /usr/local/bin/authy-ssh enable `whoami`
# test it