Skip to content

Instantly share code, notes, and snippets.

View vivithemage's full-sized avatar

Reza vivithemage

View GitHub Profile
@vivithemage
vivithemage / libmagic_example.c
Last active August 26, 2024 02:25
libmagic.h example
#include <stdio.h>
#include <magic.h>
int main(void)
{
char *actual_file = "/file/you/want.yay";
const char *magic_full;
magic_t magic_cookie;
/* MAGIC_MIME tells magic to return a mime of the file,
@vivithemage
vivithemage / boost_list_directory.cpp
Created March 12, 2014 22:18
list all files in directory with boost
#include <iostream>
#include "boost/filesystem.hpp"
using namespace std;
using namespace boost::filesystem;
int main(int argc, char *argv[])
{
// list all files in current directory.
//You could put any file path in here, e.g. "/home/me/mwah" to list that directory
@vivithemage
vivithemage / working_delay
Created May 10, 2014 20:03
arduino working delay - do things while delay is called rather than wait.
// Used instead of delay so various things can still be checked (e.g. button presses, saving data).
int workingDelay(int interval) {
unsigned long previousMillis = millis();
while(true) {
unsigned long currentMillis = millis();
Serial.println(currentMillis);
// If the current miliseconds run is more than the interval, the delay has been done, so exit.
if(currentMillis - previousMillis > interval) {
@vivithemage
vivithemage / resource_proxy.php
Last active September 18, 2018 11:02
Resource proxy with search and replace functionaltiy
<?php
/*
Resource proxy with search and replace functionality on resources (e.g. css, js) in order to get around CORS restrictions.
https://hubbounce.services.example.co.uk/?resource_url=https://example.com/wp-content/themes/example-training/dist/css/main.min.css&amp;search=url(../fonts/&amp;replace=url(https://cdn2.hubspot.net/hubfs/4668366/fonts/
*/
$resource_url = $_GET['resource_url'];
$search = $_GET['search'];
$replace = $_GET['replace'];
<?php
$filename = 'master_no_duplicates.csv';
$contents = file($filename);
function get_domain($url)
{
$pieces = parse_url($url);
$domain = isset($pieces['host']) ? $pieces['host'] : '';
if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
return $regs['domain'];
@vivithemage
vivithemage / ApprenticeshipLevyCalculator.js
Last active January 22, 2019 16:36
UK Apprenticeship Levy Calculator (javascript only)
/**
* Takes the total bill and percentage to generate the results
* @param {[type]} pay_bill [description]
* @param {[type]} percentage_in_england [description]
* @constructor
*/
function ApprenticeshipLevyCalculator(pay_bill, percentage_in_england) {
var results = {
totalLevy : (pay_bill*0.005).toFixed(0),
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.security.MessageDigest;
import java.math.BigInteger;
class md5Experiment {
public static int getDatabaseID(String domainName, int totalShards) {
byte[] bytesOfDomainName = domainName.getBytes(StandardCharsets.UTF_8);
import hashlib
import sys
def md5Experiment(domain_name, total_shards):
hash_obj = hashlib.md5(domain_name)
digest = hash_obj.hexdigest()
shard_id = int(digest, 16) % total_shards
return shard_id
# Host file to block Samsung tv adverts. List from: https://www.helpmegeek.com/block-ads-on-smart-tv-samsung-sony-lg/
# ===================================================================
0.0.0.0 config.samsungads.com
0.0.0.0 gpm.samsungqbe.com
0.0.0.0 log-config.samsungacr.com
0.0.0.0 samsung.com
0.0.0.0 samsungacr.com
0.0.0.0 samsungads.com
0.0.0.0 samsungads.com
0.0.0.0 samsungotn.net