Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Mediatek Hacker

Ascari carlosascari

:octocat:
Mediatek Hacker
  • Home
View GitHub Profile
@carlosascari
carlosascari / parse_url_search.js
Last active Feb 2, 2022
Converts param/search string in url into object
View parse_url_search.js
/**
* 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 Nov 19, 2021
Copies files and their dir structure that are modified into a gzip compressed file
View gzgitfiles.sh
git diff --no-commit-id --name-only | tar -czf modified_files.tgz -T -
@carlosascari
carlosascari / chungus.sh
Last active Jul 23, 2020
Script to find largest files in current directory
View chungus.sh
#!/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 Feb 19, 2019
Find index of a cstring in a cstring
View index_of.c
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 Nov 3, 2018
A pluggable live reload script. Works w/out a server
View livereload.js
/**!
* 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 Jun 24, 2018
jQuery-like selector. One-liner
View $.js
/**
* 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 Feb 14, 2018
OpenStreetMap database schema for api 0.6 for Sqlite
View osm06.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 Nov 22, 2017
Custom css reset (in less) based on normalize.css
View normie.less
/**
* 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 / int32.s
Created Oct 6, 2017
BIOS Calls in Protected Mode by Napalm
View int32.s
;
; 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 / svg2png.js
Created Sep 4, 2017
Converts a svg element into a png image instance
View svg2png.js
/**
* @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);