Skip to content

Instantly share code, notes, and snippets.

View ioncodes's full-sized avatar
😴
Playing with memory regions...

Layle ioncodes

😴
Playing with memory regions...
View GitHub Profile
var ionicons = document.getElementsByClassName('icon');
var icons = [];
for(var i = 0; i < ionicons.length; i++) {
if(i%10 === 0) {
icons.push(ionicons[i].className.split(' ').pop());
}
}
var ficons = document.getElementsByTagName('I');
var icons = [];
for(var i = 0; i < ficons.length; i++) {
if(ficons[i].className.indexOf(' ') === -1) {
icons.push(ficons[i].className);
}
}
var svgs = document.getElementsByClassName('icon');
var icons = [];
for(var i = 0; i < svgs.length; i++) {
var child = svgs[i].childNodes[0].getAttribute('xlink:href');
icons.push(child);
}
@ioncodes
ioncodes / u8tohex.rs
Created March 1, 2017 17:59
convert u8 to hex
use std::fmt;
struct ByteBuf<'a>(&'a [u8]);
impl<'a> fmt::LowerHex for ByteBuf<'a> {
fn fmt(&self, fmtr: &mut fmt::Formatter) -> Result<(), fmt::Error> {
for byte in self.0 {
try!(fmtr.write_fmt(format_args!("{:02x}", byte)));
}
Ok(())
}
}
@ioncodes
ioncodes / factorio_headless_guide.md
Created May 19, 2017 13:07 — forked from othyn/factorio_headless_guide.md
How to setup a Factorio Headless Server

[LINUX] Factorio Headless Server Guide

So, with credit to the Factorio wiki and cbednarski's helpful gist, I managed to eventually setup a Factorio headless server. Although, I thought the process could be nailed down/simplified to be a bit more 'tutorialised' and also to document how I got it all working for my future records.

The specific distro/version I'm using for this guide being Ubuntu Server 16.04.1 LTS. Although, that shouldn't matter, as long as your distro supports systemd (just for this guide, not a Factorio headless requirement, although most distros use it as standard now). The version of Factorio I shall be using is 0.14.20, although should work for any version of Factorio 0.14.12 and higher.

Alternate

If you prefer a simple, automated setup, [Bisa has a really handy init script that will do most of the work for

@ioncodes
ioncodes / xor.c
Last active September 2, 2018 20:01
xor two strings in c
#include <stdio.h>
#include <memory.h>
#include <stdlib.h>
#define LENGTH 5
void xor(char const value1[LENGTH], char const value2[LENGTH], char *xored[LENGTH]) {
for(int i=0; i<LENGTH; ++i) {
xored[i] = (char)(value1[i] ^ value2[i]);
}
@ioncodes
ioncodes / Qt 5 Dark Fusion Palette
Last active October 16, 2017 19:17 — forked from QuantumCD/Qt 5 Dark Fusion Palette
Qt 5 Fusion Theme
qApp->setStyle(QStyleFactory::create("Fusion"));
QPalette darkPalette;
darkPalette.setColor(QPalette::Window, QColor(53,53,53));
darkPalette.setColor(QPalette::WindowText, Qt::white);
darkPalette.setColor(QPalette::Base, QColor(25,25,25));
darkPalette.setColor(QPalette::AlternateBase, QColor(53,53,53));
darkPalette.setColor(QPalette::ToolTipBase, Qt::white);
darkPalette.setColor(QPalette::ToolTipText, Qt::white);
darkPalette.setColor(QPalette::Text, Qt::white);
@ioncodes
ioncodes / lifetime.rs
Created February 5, 2018 09:55
Small explanation how lifetimes work for @mortoray
struct Crate {
pub weight: f64,
}
/*
Rust can handle memory management on it's own.
However, Rust doesn't know how long a reference should live in a struct.
The reference may also depend on other references, etc.
Therefore we must let the compiler know how long the reference should live.
This is done with the 'lifetime specifiers'/'lifetime parameters'.
@ioncodes
ioncodes / convert.rs
Created February 5, 2018 19:57
Convert u32 to u8 slice with Big Endian and Little Endian support!
let bytes: [u8; 4] = unsafe { transmute(0u32.to_le()) }; // or to_be
@ioncodes
ioncodes / sign.sh
Created February 6, 2018 15:19
Fix .app is damaged in Mac OS X without disabling Gatekeeper. Also fixes "code object is not signed at all"
sudo codesign --force --sign --deep - /Applications/YourApp.app