Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Foukarakis mfukar

View GitHub Profile
@mfukar
mfukar / download_owned_cards.ps1
Last active Sep 7, 2020
[Tyrant Unleashed] Download your cards into a ownedcards.txt file, and your decks into a currentdecks.txt, for use with the optimiser. From your browser, get the response from the api.php?message=init request into a file named json.txt in the /data/ directory of the optimiser, along with this script. Reqs Powershell 7. Will create two files in t…
View download_owned_cards.ps1
$stopwatch = [Diagnostics.Stopwatch]::StartNew()
if (-not (Test-Path "json.txt")) {
Write-Host "[-] To update owned cards, supply the response to api.php?message=init in json.txt"
exit 1
}
$account_details = Get-Content "json.txt" | ConvertFrom-JSON -AsHashtable
if (-not (Test-Path "cards_section*.xml")) {
Write-Host "[-] Run this script inside the optimiser's /data/ directory"
@mfukar
mfukar / download_owned_cards.ps1
Created Jul 8, 2020
[Tyrant Unleashed] Download your cards into a ownedcards.txt file for use with the optimiser.
View download_owned_cards.ps1
if (-not (Test-Path "json.txt")) {
"[-] To update owned cards, supply the response to api.php?message=init in json.txt"
exit 1
}
$account_details = [String](get-content "json.txt")
if (-not (Test-Path "cards_section*.xml")) {
"[-] Run this script inside the optimiser's /data/ directory"
exit 2
}
View countdown.cpp
/**
* Solver for the Countdown numbers game. Branch-and-bound search.
* Compile with:
* clang++ -std=c++17 -O3 -o countdown countdown.cpp
*
* Should find answers in much less than a second.
*/
#include <limits>
#include <vector>
#include <string>
@mfukar
mfukar / com.local.jekyll.server.agent.plist
Created Aug 14, 2017
macos LaunchAgent to debug, test, and serve a Github page locally
View com.local.jekyll.server.agent.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.local.jekyll.server.agent</string>
<key>ProgramArguments</key>
<array>
<string>PATH_TO_YOUR_BUNDLE_BINARY_OR_WRAPPER</string>
@mfukar
mfukar / luhn.cpp
Last active Jun 23, 2017
The Luhn test in C++11
View luhn.cpp
#include <algorithm>
#include <numeric>
#include <iostream>
#include <vector>
bool luhn (const std::string & id) {
static const int m[] = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9};
bool is_odd = false;
auto lambda = [&](int a, char c) {
return a + ((is_odd = !is_odd) ? c - '0' : m[c - '0']);
@mfukar
mfukar / z3-salsa10.py
Last active Sep 3, 2020
Recover the key used by Petya to encrypt the MFT
View z3-salsa10.py
# Recover the key used by the Petya ransomware to encrypt the MFT (master file table)
import z3
import sys, struct
# XOR key for salsa10-src.bin :
KEY_SECTOR = 0x37
# Counter position, as two words
CNTLO = 0
CNTHI = 0
@mfukar
mfukar / terminate-worker-threads.c
Last active Jun 6, 2020
C11 code to have a POSIX multithreaded application which signal work completion via a condition variable, and then terminate.
View terminate-worker-threads.c
#include <unistd.h>
#include <stdbool.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#define NUM_THREADS 10
pthread_mutex_t cv_mutex;
pthread_cond_t notification_cv;
@mfukar
mfukar / vmware.py
Created May 26, 2016
Some interview question from VMware. Figure out the problem statement, it's obvious.
View vmware.py
import sys
def main():
N = raw_input()
elements = [int(element) for element in sys.stdin.read().split(' ')]
L, R = 0, len(elements)
# We got ourselves a maximum subarray problem, with inverted semantics.
# The subarray we want to find is the one to flip all the bits in.
@mfukar
mfukar / reasonable-tuple.cpp
Created Apr 30, 2016
Use an std::tuple without magic numbers and the stupid get<> interface
View reasonable-tuple.cpp
#include <tuple>
struct Cache;
template<int, typename> struct cache_getter;
template<int, typename...> struct tuple_walker;
template<int I, typename... Ts> struct cache_getter<I, std::tuple<Ts...> > {
static std::tuple<Ts...> get(Cache & c);
};
@mfukar
mfukar / nuke-noscript.user.js
Last active Mar 24, 2016
Nuke <noscript> tags
View nuke-noscript.user.js
// ==UserScript==
// @name nuke noscript
// @namespace https://gist.github.com/mfukar/d1dd369deaa7c3941fde
// @version 0.2
// @description Remove all <noscript> tags in every document
// @author mfukar
// @grant none
// ==/UserScript==
/* jshint -W097 */
'use strict';