Skip to content

Instantly share code, notes, and snippets.

View bitsmanent's full-sized avatar

Claudio Alessi bitsmanent

  • Italy
View GitHub Profile
@agapas
agapas / dirReduc.js
Created December 2, 2017 14:20
trivia (javascript) - dirReduc
/*
Once upon a time, on a way through the old wild west,…
… a man was given directions to go from one point to another. The directions were "NORTH", "SOUTH", "WEST", "EAST". Clearly "NORTH" and "SOUTH" are opposite, "WEST" and "EAST" too. Going to one direction and coming back the opposite direction is a needless effort. Since this is the wild west, with dreadfull weather and not much water, it's important to save yourself some energy, otherwise you might die of thirst!
How I crossed the desert the smart way.
The directions given to the man are, for example, the following:
["NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST"].
You can immediatly see that going "NORTH" and then "SOUTH" is not reasonable, better stay to the same place!
So the task is to give to the man a simplified version of the plan.
A better plan in this case is simply:
["WEST"]
@palopezv
palopezv / dwm_config_pulseaudio.h
Last active April 27, 2026 17:02 — forked from neuro-sys/dwmconfig.h
dwm volume control with hardware multimedia keys (pipewire, pulseaudio, amixer and light as an extra)
/**
* dwmconfig.h
* Hardware multimedia keys
*/
/* Somewhere at the beginning of config.h include: */
/*
You obviously need the X11 development packages installed, X11proto in particular, but
here is the location of the keysyms header upstream copy if you can't bother
using the contents of your own hard drive. ;-P
@Arinerron
Arinerron / root.sh
Last active March 7, 2026 01:47
"Root" via dirtyc0w privilege escalation exploit (automation script) / Android (32 bit)
#!/bin/bash
# Give the usual warning.
clear;
echo "[INFO] Automated Android root script started.\n\n[WARN] Exploit requires sdk module \"NDK\".\nFor more information, visit the installation guide @ https://goo.gl/E2nmLF\n[INFO] Press Ctrl+C to stop the script if you need to install the NDK module. Waiting 10 seconds...";
sleep 10;
clear;
# Download and extract exploit files.
echo "[INFO] Downloading exploit files from GitHub...";
@avafloww
avafloww / PhpJava.java
Last active August 12, 2025 13:33
This snippet of code is syntactically valid in both PHP and Java, and produces the same output in both.
/*<?php
//*/public class PhpJava { public static void main(String[] args) { System.out.printf("/*%s",
//\u000A\u002F\u002A
class PhpJava {
static function main() {
echo(//\u000A\u002A\u002F
"Hello World!");
}}
//\u000A\u002F\u002A
PhpJava::main();

Why I hate TypeScript

Warning: These views are highly oppinated and might have some slightly incorrect facts. My experience with typescript was about 2 weeks in Node and a week in angular2.

Not Standard

TypeScript is implementing their own take on JavaScript. Some of the things they are writing will likely never make it in an official ES* spec either.

Technologies that have competing spec / community driven development have a history of failing; take: Flash, SilverLight, CoffeeScript, the list goes on. If you have a large code base, picking TypeScript is something your going to be living with for a long time. I can take a bet in 3 years JavaScript will still be around without a doubt.

Its also worth noting that they have built some things like module system and as soon as the spec came out they ditched it and started using that. Have fun updating!

@bitsmanent
bitsmanent / strgeo
Last active October 17, 2015 10:07
Take a string representing a location and returns a formatted political name and coordinates
function strgeo($target) {
$str = rawurlencode($target);
$uri = "http://maps.googleapis.com/maps/api/geocode/json?address=${target}&sensor=true";
$d = json_decode(file_get_contents($uri), 1);
$d = (@$d['results'][0]);
if(!$d)
return NULL;
return [
'targetf' => $d['formatted_address'],
'coords' => $d['geometry']['location'],
@bitsmanent
bitsmanent / mkview.js
Last active January 25, 2018 16:22
Build a view from a template and a data set. Replace %{key} with the corresponding value.
function mkview(tpl, d) {
var ret = tpl, re, k;
for(k in d) {
re = new RegExp("%{"+k+"}", "g");
ret = ret.replace(re , d[k]);
}
return ret;
}
@bitsmanent
bitsmanent / xhr.js
Last active January 18, 2017 16:05
Send XMLHttpRequest requests
function xhr(method, hdrs, action, data, callback) {
var r = new XMLHttpRequest();
r.onreadystatechange = function() {
if(r.readyState == 4 && r.status == 200)
callback(JSON.parse(r.responseText)); /* always expect JSON */
};
switch(method.toUpperCase()) {
case "POST":
@bitsmanent
bitsmanent / serialize.js
Last active October 24, 2015 17:19
Encode an object as a string
function serialize(obj, _name) {
var i, pfx, tp, str = [];
if(!obj)
return _name;
tp = typeof obj;
if(obj.length && tp != 'object' && tp != 'string') { /* pure arrays */
for(i = 0; i < obj.length; ++i) {
pfx = (_name ? _name+'['+i+']' : i);
str.push(pfx+'='+obj[i]);
}
@bitsmanent
bitsmanent / collects.js
Last active October 11, 2016 19:05
Returns a serializable object of the given elements. Requires deepset().
function collects(elems) {
var i, len, v, keys = null, ret = {};
len = elems ? elems.length : 0;
for(i = 0; i < len; ++i) {
if(!elems[i].name)
continue;
keys = elems[i].name.replace(/\[([^\]]*)\]/g, ",$1").split(',');
v = (elems[i].type == "checkbox" ? (elems[i].checked ? elems[i].value : "") : elems[i].value);
deepset(ret, keys, v);