Skip to content

Instantly share code, notes, and snippets.

@reporter123
reporter123 / ng-completion.sh
Last active June 26, 2022 16:13
Partial bash completion for ng. This is a more functional version than the two liner in circulation.
_ng() {
local cur prev opts
local NG_COMMANDS="add build config doc e2e generate help lint new run serve test update version xi18n"
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--help"
posopts="${NG_COMMANDS}"
@reporter123
reporter123 / NodeSystemError.ts
Last active December 3, 2022 01:53
Compelete typescript definition for node's SystemError. A partial definition exists within TypeScript.
/*
Missing from TypeScript but documented by node.
See https://nodejs.org/api/errors.html#class-systemerror
*/
interface NodeSystemError extends Error{
address?: string; //If present, the address to which a network connection failed
code:string;// The string error code
@reporter123
reporter123 / nstrtol
Created February 17, 2018 03:19
strtol with a lenght limit.
long nstrtol(const char *string, size_t len)
{
long sig = 1;
long value = 0;
size_t i = 0;
if(string[0] == '-')
sign *= -1, i++;
for(; len > 0 && isdigit(string[i]); i++, len--)
@reporter123
reporter123 / printenvdemo.cpp
Created January 15, 2018 01:52
Hidden third parameter to main
#include<stdio.h>
int main(int argc, char** argv, char** env)
{
int i = 0;
while(env[i] != 0)
{
printf("%s\n", env[i++]);
}
return(0);
}
@reporter123
reporter123 / bash.env
Last active April 29, 2018 18:12
My /etc/bash.env
#block automatic logs created by bzr but tell it to send them to /dev/null
export BZR_LOG=/dev/null
#force use of system look and feel I am not affected by the hangs/crashes
export CALIBRE_USE_SYSTEM_THEME=1
# fix python's ascii-127 addiction.
export PYTHONIOENCODING='utf_8'
#These may trigger strange issues with modules not tested on unicode yet but my terminal is UTF-8 by default anyway.
@reporter123
reporter123 / cc
Last active January 7, 2018 19:04
Work around to enable color output when using ccache + update-altertentives with clang.
#! /bin/bash
cc.debian -fdiagnostics-color=auto $*
@reporter123
reporter123 / reIndexOf.js
Created April 24, 2017 02:09
Adds a regEx based indexOf function to the Array prototype.
//install helper funtion not found in javascript
/** * Regular Expresion IndexOf for Arrays
* This little addition to the Array prototype will iterate over array
* and return the index of the first element which matches the provided
* regular expresion.
* Note: This will not match on objects.
* @param {RegEx} rx The regular expression to test with. E.g. /-ba/gim
* @return {Numeric} -1 means not found */
if (typeof Array.prototype.reIndexOf === 'undefined') {
@reporter123
reporter123 / noroot.sh
Created December 29, 2016 02:50
Makes itop and wireshark work withouth root. Requires a linux kernel with capabilities enabled.
#!/bin/sh
setcap "CAP_NET_ADMIN,CAP_NET_RAW+eip" `which iotop`
setcap "CAP_NET_ADMIN,CAP_NET_RAW+eip" `which dumpcap`
@reporter123
reporter123 / application-x-kdeuser1.xml
Created November 3, 2016 02:54
Magic file for shared-mime-info to reconize appleworks documents.
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-kdeuser1">
<comment>AppleWorks File</comment>
<magic-deleteall/>
<magic>
<match type="byte" offset="1" value="0x07">
<match type="string" offset="4" value="BOBO"/>
</match>
</magic>
@reporter123
reporter123 / appleworks
Created October 17, 2016 01:42
magic for file command to reconize Appleworks documents.
# appleworks: file(1) magic for appleworks(v4,v6) documents
# Apple Works a word processor file
# Version 4.?,6.2.9
# .cwk extention optional, MacOS Creator code:'BOBO'
1 byte =0x07
>4 string BOBO
>>0 byte =0x04 AppleWorks 4 Document
>>0 byte =0x06 AppleWorks 6 Document