Skip to content

Instantly share code, notes, and snippets.

@nikopol
nikopol / .zshrc
Created October 25, 2011 12:08
niko's zshrc
# niko's zsh conf
### VARIABLES
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
export EDITOR="vim"
export PAGER="vimpager"
export PATH="${PATH}:${HOME}/bin"
@nikopol
nikopol / is_utf8.pl
Created November 2, 2011 17:53
is_utf8 perl vs inline c
#!/usr/bin/perl -w
use Inline C;
#use Benchmark qw(:all);
local $/=undef;
my $file=$ARGV[0] or die("you must specify a file");
open my $fh, "<", $file;
my $text=<$fh>;
@nikopol
nikopol / gist:1583367
Created January 9, 2012 15:18
dancer params test
#!/usr/bin/perl
use Dancer;
use Data::Dump;
prefix '/test';
get '/' => sub {
my $params = params;
"<pre>params:" . Data::Dump::dump($params) . "</pre>";
@nikopol
nikopol / dancer_mem_leak.pl
Created January 12, 2012 10:38
dancer memory leak
#!/usr/bin/env perl
use strict;
use warnings;
use Dancer;
#return memory used by the current pid
sub memused {
sysopen(my $fh, "/proc/$$/statm", 0) or die $!;
sysread($fh, my $line, 255) or die $!;
@nikopol
nikopol / minify
Created February 10, 2012 18:24
html/php minifier
#!/usr/bin/env perl
#html/php minifier - niko 2012
#use: ./minify < tof.php > ../index.php
use strict;
use warnings;
use JSON;
use LWP::UserAgent;
use MIME::Base64;
@nikopol
nikopol / Net-OAuth2-refresh
Created April 5, 2012 10:46
Net-OAuth2 with refresh sample usecase
#load token if previously saved
if( my $data = read_file( $tokenfile ) ) {
$self->{token} = $data;
}
#instanciate api with token_or_undef
$self->{api} = Net::OAuth2::Client->new(
$self->{client_id},
$self->{client_secret},
@nikopol
nikopol / touchpad.sh
Created May 7, 2012 11:11
touchpad enabler/disabler
#!/bin/bash
DEVID=`xinput list | grep -i touchpad | egrep -o 'id=(\w+)' | sed 's/id=//'`
[[ "$1" == "on" ]] && xinput set-prop $DEVID "Device Enabled" 1
[[ "$1" == "off" ]] && xinput set-prop $DEVID "Device Enabled" 0
echo -n "touchpad device #$DEVID "
if [[ "`xinput list-props $DEVID | grep -i enabled | egrep -o '\w$'`" == "1" ]]
then echo "is enabled"
else echo "is disabled"
fi
@nikopol
nikopol / hi
Last active October 13, 2017 15:52
hostinfo
#!/usr/bin/env perl
#niko h[ost]i[nfo]
use strict;
use warnings;
use utf8;
use 5.010;
my $VERSION = '0.3';
@nikopol
nikopol / jsmin
Created October 15, 2012 14:27
js minifier [file.js [file.min.js]]
#!/usr/bin/env perl
#js minifier using google clojure WS api
#usages:
#./jsmin < file.js > file.min.js #input=stdin output=stdout
#./jsmin file.js #input=file.js output=file.min.js
#./jsmin file.js file.min.js #input=file.js output=file.min.js
use strict;
use warnings;
@nikopol
nikopol / csvcount.c
Created October 19, 2015 13:42
LIGTHNING FAST CSV ROW COUNT
/*
LIGTHNING FAST CSV ROW COUNT
syntax: csvcount filename
niko 2015
*/
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>