Skip to content

Instantly share code, notes, and snippets.

View carlosascari's full-sized avatar
:octocat:
Mediatek Hacker

Ascari carlosascari

:octocat:
Mediatek Hacker
  • Home
View GitHub Profile
@carlosascari
carlosascari / int32.s
Created October 6, 2017 02:36
BIOS Calls in Protected Mode by Napalm
;
; Protected Mode BIOS Call Functionailty v2.0 - by Napalm
; -------------------------------------------------------
;
; This is code shows how its POSSIBLE to execute BIOS interrupts
; by switch out to real-mode and then back into protected mode.
;
; If you wish to use all or part of this code you must agree
; to the license at the following URL.
;
@carlosascari
carlosascari / parse_url_search.js
Last active February 2, 2022 23:31
Converts param/search string in url into object
/**
* Converts param/search string component from a url into an object
* Uses `location.search` as input string
*/
Object.assign.apply({}, location.search.substr(1).split('&').map(x => x.split('=').reduce((a, b) => { return { [a]: b } })))
@carlosascari
carlosascari / gzgitfiles.sh
Created November 19, 2021 23:11
Copies files and their dir structure that are modified into a gzip compressed file
git diff --no-commit-id --name-only | tar -czf modified_files.tgz -T -
@carlosascari
carlosascari / chungus.sh
Last active July 23, 2020 00:41
Script to find largest files in current directory
#!/bin/bash
# Top 20 Files
find -type f -exec du -Sh {} + | sort -rh | head -n 20
# Top 20 Dirs
du -Sh | sort -rh | head -20
du -a . | sort -n -r | head -n 20
@carlosascari
carlosascari / index_of.c
Created February 19, 2019 23:22
Find index of a cstring in a cstring
int index_of(char* hay, char* needle, size_t start) {
size_t len = strlen(hay);
size_t needle_len = strlen(needle);
int subfind = 0;
for (int j = start; j < len; ++j)
{
if (hay[j] == needle[0]) {
subfind = 1;
for (int k = 1; k < needle_len; ++k)
{
@carlosascari
carlosascari / livereload.js
Last active November 3, 2018 03:11
A pluggable live reload script. Works w/out a server
/**!
* A pluggable live reload script. No server required.
* Will reload page whenever the page content or link & script
* resources change.
* A reload will only be triggered when the page/window has focus.
*/
// https://gist.github.com/carlosascari/cc85e74544e4a26dcd88e94eb7a281ea
import $ from '$';
@carlosascari
carlosascari / $.js
Last active June 24, 2018 05:34
jQuery-like selector. One-liner
/**
* jQuery selector substitute
* A quick one-liner for a jQuery-like selector, when a project
* does not need the extra weight early on, but may need jQuery later on.
* @param {String} query - CSS selector
* @param {HTMLElement} context - Element to query, defaults to `document`
* @return {Array<Element>}
*/
$ = (query, context=document) => Array.prototype.slice.call(context.querySelectorAll(query));
@carlosascari
carlosascari / osm06.sqlite
Created February 14, 2018 18:59
OpenStreetMap database schema for api 0.6 for Sqlite
--
-- OpenStreetMap database schema for api 0.6
--
PRAGMA synchronous = OFF;
PRAGMA journal_mode = MEMORY;
BEGIN TRANSACTION;
CREATE TABLE acls(
@carlosascari
carlosascari / normie.less
Last active November 22, 2017 06:54
Custom css reset (in less) based on normalize.css
/**
* Copyright(c) 2017 Carlos Ascari Gutierrez Hermosillo.
* MIT License.
*/
// Based on normalize.css 7.0.0
// https://github.com/necolas/normalize.css/tree/7.0.0
// + This version allows removing IE support by version as well as
// as hiding rarely used tags.
@carlosascari
carlosascari / svg2png.js
Created September 4, 2017 20:31
Converts a svg element into a png image instance
/**
* @param {SVGSVGElement} svg
* @param {Number} [w] Width of png image. Default: 128
* @param {Number} [h] Height of png image. Default: 128
* @return {Image} png image
*/
const svg2png = (svg, w=128, h=128) => {
svg.setAttribute('width', `${w}px`);
svg.setAttribute('height', `${h}px`);
const xml = new XMLSerializer().serializeToString(svg);