Skip to content

Instantly share code, notes, and snippets.

View h2rd's full-sized avatar

Igor Skrynkovskyy h2rd

  • Route4Me
  • Lviv, Ukraine
View GitHub Profile
@h2rd
h2rd / gist:4198748
Created December 3, 2012 22:32
console get key
var keypress = require('keypress')
, tty = require('tty');
// make `process.stdin` begin emitting "keypress" events
keypress(process.stdin);
// listen for the "keypress" event
process.stdin.on('keypress', function (ch, key) {
console.log('got "keypress"', key.name);
if (key && key.ctrl && key.name == 'c') {
@h2rd
h2rd / gist:4198919
Created December 3, 2012 23:03
javascript random hex
var hex = (Math.random()*0xFFFFFF<<0).toString(16);;
@h2rd
h2rd / gist:4204482
Created December 4, 2012 14:29
Strip html, xml and keep only text
try:
import lxml.html
def striphtml(data):
t = lxml.html.fromstring(data)
return t.text_content()
except:
import re
def striphtml(data):
t = re.compile(r'<.*?>')
return t.sub('', data)
@h2rd
h2rd / gist:4220577
Created December 5, 2012 23:46
remove .svn folders in subdirectories
find . -name ".svn" -exec rm -rf {} \;
@h2rd
h2rd / gist:4232244
Created December 7, 2012 10:00
get terminal size nodejs
console.log(process.stdout.getWindowSize());
@h2rd
h2rd / gist:4298452
Created December 15, 2012 19:31
Backbone fetch with parameters
MessageList = Backbone.Collection.extend({
initialize: function(models, options) {
options = options || {};
this.offset = options.offset || 0;
this.limit = options.limit || 30;
this.sortBy = options.sortBy || 'by_desc';
},
url: function() {
@h2rd
h2rd / gist:4464755
Created January 6, 2013 01:58
get random color
"#"+((1<<24)*Math.random()|0).toString(16)
@h2rd
h2rd / gist:4466715
Created January 6, 2013 11:57
hook
svn export file:///path/ . --force
@h2rd
h2rd / gist:4511079
Created January 11, 2013 14:33
Alert in object-c
NSAlert *alert = [[NSAlert alloc] init];
[alert setAlertStyle:NSInformationalAlertStyle];
[alert setMessageText:@"Message text"];
[alert setInformativeText:@"Info text"];
[alert runModal];
NSMutableArray *arr = [[NSMutableArray alloc]init];
for(int i=0;i<=10;i++) {
NSString *nm=[NSString stringWithFormat:@"Raju %d",i];
[arr addObject:nm];
}
NSLog(@"%lu", [arr count]);