Skip to content

Instantly share code, notes, and snippets.

View clupasq's full-sized avatar

Cristian Lupașcu clupasq

View GitHub Profile
(function(){
var styleId = 'invert-style';
var style = document.getElementById(styleId);
if (style) {
style.parentElement.removeChild(style);
} else {
style = document.createElement('style');
style.id = styleId;
style.textContent = '' +
'html,img, video, object, [style*=url] {' +
@clupasq
clupasq / codio_init.sh
Last active July 20, 2020 21:09
Codio init
cd ~
mkdir -p ~/.config
sudo apt-get install -y inotify-tools
sudo apt-get install -y tmux
git clone https://github.com/clupasq/clupasq.git $HOME/.config/clupasq
$HOME/.config/clupasq/setup.sh -o
@clupasq
clupasq / js_test.js
Created June 8, 2015 14:32
JavaScript Simple Asserts
function assertEquals(expected, actual){
if(expected === actual){
console.info('OK');
} else {
console.error('(' + expected + ') !== (' + actual + ') !!!');
}
}
function assertThrows(f){
try{
@clupasq
clupasq / awesome-git-setup.sh
Last active September 15, 2017 09:07
Awesome git prompt for Linux
# Creates a script that will:
# - customize the prompt to use posh-git-sh
# - add git-completion
DIRECTORY=~/.awesome-git-prompt
SCRIPT=~/git-prompt.sh
if [ ! -d "$DIRECTORY" ]; then
mkdir "$DIRECTORY"
@clupasq
clupasq / gist:fd00f20ba537408d1a0b
Created February 20, 2015 22:14
Programming Puzzles and Code Golf character counter for answers
/* stolen from http://stackoverflow.com/a/5515960/390819 */
function lengthInUtf8Bytes(str) {
/* Matches only the 10.. bytes that are non-initial characters in a multi-byte sequence. */
var m = encodeURIComponent(str).match(/%[89ABab]/g);
return str.length + (m ? m.length : 0);
}
var answers = document.querySelectorAll('div.answer');
var codeBoxes = Array.prototype.map.call(answers, function(a){
@clupasq
clupasq / car_van.js
Created February 13, 2015 12:04
JavaScript Pseudoclassical Subclass example
console.clear();
function Car(name, loc) {
this.name = name;
this.loc = loc;
}
Car.prototype.move = function(){
this.loc++;
console.log(this.name + "'s location is now " + this.loc.toString());
};
@clupasq
clupasq / memo.py
Created January 24, 2015 21:49
Python memoisation decorator
# taken from the "Design of Computer Programs" course by Peter Norvig
# https://www.udacity.com/course/cs212
from functools import update_wrapper
def decorator(d):
"Make function d a decorator: d wraps a function fn."
def _d(fn):
return update_wrapper(d(fn), fn)
update_wrapper(_d, d)
@clupasq
clupasq / Codio Default Prefs
Last active August 29, 2015 14:11
Exercism guard -d with `LISTEN_GEM_DEBUGGING=2`
[editor]
;Show line numbers.
; Type: boolean
line_numbers = true
;Visible tabs.
; Type: boolean
visible_tabs = false
@clupasq
clupasq / so_notifier.js
Last active August 29, 2015 14:10
StackOverflow New Question Sound Notification
(function () {
'use strict';
var model = {
alarmActive: true
};
var controller = {
init: function() {
if (this.alreadyRunning()) {
@clupasq
clupasq / gist:44097e5c2c2baca54903
Created November 4, 2014 20:01
VIM macro to run Ruby
map ,t :w\|!ruby %<cr>