Skip to content

Instantly share code, notes, and snippets.

java-ing and python-ing

Giacomo Lacava toyg

java-ing and python-ing
Block or report user

Report or block toyg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
toyg /
Last active Jul 7, 2019
Example Flask app showing how to manage a webapp-style authentication flow with python-o365(once/if my PR is accepted - in meantime, can be used with toyg/python-0365 on the webapp_flow branch)
# when testing locally, set environment variable OAUTHLIB_INSECURE_TRANSPORT to 1
# so you can use http://localhost... in redirect
import os
from O365 import Connection
from flask import Flask, redirect, request, url_for, abort
# O365 secrets
APP_ID = os.environ.get('O365_APP_ID')
APP_PWD = os.environ.get('O365_APP_PWD')
toyg /
Last active Jan 28, 2019
Utility methods to mock HTTP calls made with the Apache Commons HttpClient fluent interfaces. It allows simple specification of url, expected response, simple headers, and body. This is enough for my current needs, feel free to suggest other commonly-used sub-interfaces that should be mocked in this scenario.
package com.autoepm.versioner.common;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.fluent.Executor;
import org.apache.http.client.fluent.Response;
import org.apache.http.message.BasicHeader;
import org.mockito.ArgumentCaptor;
toyg / nic_metrics.ps1
Created Nov 2, 2017
Manually set Windows "Metrics" values for network cards. When a server has multiple cards, you are often forced to disable Windows' automatic "metrics", to make sure EPM traffic goes on the right interface.
View nic_metrics.ps1
# To use this script, rename LAN, BACKUP etc to match relevant network card names
# in your environment (you can add or remove lines as well),
# and set values to match your metric preference (1 is the preferred card).
# All cards not mentioned here will be set to 100.
$cards = @{} # don't touch this line
$cards.LAN = 1
$cards.BACKUP = 99
toyg / query_EPM_COMPONENTS.ps1
Created Nov 2, 2017
Query a Foundation database to retrieve EPM Component data from SQLServer. This uses the .NET SqlClient assembly, so will work from any .NET 2.0 computer
View query_EPM_COMPONENTS.ps1
#requires -Version 1
$SQLconn = New-Object -TypeName System.Data.SqlClient.SqlConnection -ArgumentList ('server=ardy-sql01; database=foundation; uid=EPMSQL; pwd=Hyp3r10n')
$SQLcmd = $SQLconn.CreateCommand()
$SQLcmd.CommandType = [System.Data.CommandType]::Text
$SQLcmd.CommandText =
$data = $SQLcmd.ExecuteReader()
$dataTable = New-Object -TypeName 'System.Data.DataTable'
toyg / Get-ServiceUpTime.ps1
Created Nov 2, 2017
PowerShell Function to query each service and show the start time from the associated process
View Get-ServiceUpTime.ps1
function Get-ServiceUpTime
# Name of Computer(s) to query
[Parameter(Mandatory = $false,
Position = 1,
ValueFromPipelineByPropertyName = $true)]
[string[]]$ComputerName = $env:COMPUTERNAME,
View error.txt
/usr/local/Cellar/cmake/3.9.0/bin/cmake -H/Users/toyg/Dev/waifu2x-dev -B/Users/toyg/Dev/waifu2x-dev --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.9.0/bin/cmake -E cmake_progress_start /Users/toyg/Dev/waifu2x-dev/CMakeFiles /Users/toyg/Dev/waifu2x-dev/CMakeFiles/progress.marks
/Applications/ -f CMakeFiles/Makefile2 all
/Applications/ -f CMakeFiles/conv.dir/build.make CMakeFiles/conv.dir/depend
cd /Users/toyg/Dev/waifu2x-dev && /usr/local/Cellar/cmake/3.9.0/bin/cmake -E cmake_depends "Unix Makefiles" /Users/toyg/Dev/waifu2x-dev /Users/toyg/Dev/waifu2x-dev /Users/toyg/Dev/waifu2x-dev /Users/toyg/Dev/waifu2x-dev /Users/toyg/Dev/waifu2x-dev/CMakeFiles/conv.dir/DependInfo.cmake --color=
/Applications/ -f CMakeFiles/conv.dir/build.make CMakeFiles/conv.dir/build
make[2]: Nothing to be done for `CMakeFiles/conv.dir/build'.
[ 8%] Built target conv
toyg / CMakeError.log
Last active Oct 21, 2017
waifu2x error
View CMakeError.log
Determining if the CL_VERSION_2_0 exist failed with the following output:
Change Dir: /Users/toyg/Dev/waifu2x-dev/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_90b7e/fast"
/Applications/ -f CMakeFiles/cmTC_90b7e.dir/build.make CMakeFiles/cmTC_90b7e.dir/build
Building C object CMakeFiles/cmTC_90b7e.dir/CheckSymbolExists.c.o
/Applications/ -o CMakeFiles/cmTC_90b7e.dir/CheckSymbolExists.c.o -c /Users/toyg/Dev/waifu2x-dev/CMakeFiles/CMakeTmp/CheckSymbolExists.c
/Users/toyg/Dev/waifu2x-dev/CMakeFiles/CMakeTmp/CheckSymbolExists.c:8:19: error: use of undeclared identifier 'CL_VERSION_2_0'
return ((int*)(&CL_VERSION_2_0))[argc];
toyg /
Last active Aug 26, 2017
IT books downloader
# original source:
# plus a few tweaks from me.
# This is a Python 2.7 script; you will also need Requests and BeautifulSoup.
# If you have virtualenv installed:
# $> virtualenv env
# $> source env/bin/activate
# $> pip install requests beautifulsoup
# $> python
import codecs
toyg / Synopsifier.user.js
Last active Jun 25, 2018
View Synopsifier.user.js
// ==UserScript==
// @name Synopsifier
// @namespace
// @version 1.0
// @description add movie details when browsing directories.
// @author toyg
// @match*
// @grant GM_xmlhttpRequest
// @connect
// ==/UserScript==
toyg /
Last active May 25, 2016
Change Login background image in OSX. Execute with sudo; takes 1 parameter, the path to your new file (must be a PNG image).
chflags nouchg /Library/Caches/
cp /Library/Caches/ /Library/Caches/
cp $1 /Library/Caches/
chflags uchg /Library/Caches/
You can’t perform that action at this time.