Skip to content

Instantly share code, notes, and snippets.

View rjloura's full-sized avatar

Rui Loura rjloura

View GitHub Profile
@rjloura
rjloura / ip2long.js
Last active October 1, 2016 14:26
ip2long
var ipv4_to_long = function(dots) {return ((((((+dots[0])*256)+(+dots[1]))*256)+(+dots[2]))*256)+(+dots[3]);};
/*
* For IPv6 the "calculation" is easier because the max of each halfword is 'ffff', but we cant be as accurate because
* the value will usually be > Number.MAX_SAFE_INTEGER. So the function below will only give you the answer in SI notation.
*/
var ipv6_to_long = function(v6addr) {parseInt(addr.replace(/:/g, ''), 16);};
@rjloura
rjloura / ipv6.py
Created October 1, 2016 14:29
Convert IP adress strings
# TODO: Make this work with compressed format
def ipv6_to_decimal(addr):
return (int(addr.replace(':', ''), 16))
@rjloura
rjloura / queryset2js.py.js
Created January 18, 2017 01:37
Convert queryset to JSON for use with javascript
Using the JSONEncoder from: https://github.com/bradjasper/django-jsonfield/blob/master/jsonfield/encoder.py
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)
tl = Model.objects.filter(year=self.kwargs['year']).values()
ctx['jsonstring'] = json.dumps(tl, cls=JSONEncoder)
return ctx
Then in the template:
var json_data = {{ jsonstring|safe }};
@rjloura
rjloura / compress_avi_to_mp4.sh
Created February 2, 2017 17:00
Single ffmpeg command to compress raw avi into mp4
#!/bin/bash
# Will need to install 'libfaac0'
# '-strict -2' to allow experimental
# set '-preset veryslow' for better compression
# set '-crf' lower to get better quality (default is 23, I think)
ffmpeg -i input.avi -strict -2 -c:v libx264 -crf 19 -preset slow -c:a aac -b:a 192k -ac 2 out.mp4

Keybase proof

I hereby claim:

  • I am rjloura on github.
  • I am rjloura (https://keybase.io/rjloura) on keybase.
  • I have a public key whose fingerprint is 1C91 E340 FC48 C37C BCEE A2AE 997E 6BF0 FAEB CE04

To claim this, I am signing this object:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
=
This message has been signed by keybase.io/rjloura. The signature can be
verfified at https://keybase.io/verify.
=
Encryption can be easy these days, and Facebook is anything but private.
Please contact me instead on these more secure services (in order of preference):
@rjloura
rjloura / sortAlphaNum.js
Last active July 6, 2017 14:59
Sorting AlphaNumeric Strings in Javascript
/* Straight copy from https://stackoverflow.com/questions/4340227/sort-mixed-alpha-numeric-array */
/* Note that the ^ in [^xyz] creates a negated character set, and does not match the beginning of the line. */
var reA = /[^a-zA-Z]/g;
var reN = /[^0-9]/g;
function sortAlphaNum(a,b) {
var aA = a.replace(reA, "");
var bA = b.replace(reA, "");
if(aA === bA) {
var aN = parseInt(a.replace(reN, ""), 10);
@rjloura
rjloura / gocscope.sh
Created September 5, 2017 14:00
Building cscope xref for golang
# Build cscope xref for Golang. Works well for "Find this C symbol", but not very well for definitions.
# Assuming you're in the project Root:
#Find the files
find . -name '*.go' > cscope.files
#Build the xref
cscope -b -k
@rjloura
rjloura / coal_create.sh
Last active April 4, 2018 21:55
Create COAL on VirtualBox
#!/usr/bin/bash -x
#
# Creating a COAL on VirtualBox. (Still WIP)
#
# This guide assumes you've run "make coal" in your sdc-headnode workspace,
# and copied over the files below from the VMWARE directory to your VBDIR:
# zpool.vmdk
# 4gb.img
# USB-Headnode.vmdk
#
@rjloura
rjloura / xfce_caps_to_escape.md
Last active January 15, 2021 10:22
How to set capslock to escape key in xfce4

My chromebook doesn't have a caps lock key, it has a "search" key. When running crouton xfce4 is unaware of this key in the keybaord mappings GUI. This is how I ended up mapping the search/capslock key to escape.

  1. Run xev(1)
  2. Strike the capslock (aka search, or super_L key) and ook for entries like the following:
KeyPress event, serial 28, synthetic NO, window 0x2600001,
    root 0xd3, subw 0x0, time 16308538, (449,411), root:(1043,703),
    state 0x0, keycode 133 (keysym 0xff1b, Escape), same_screen YES,
    XKeysymToKeycode returns keycode: 9
 XLookupString gives 1 bytes: (1b)