Skip to content

Instantly share code, notes, and snippets.

View samsonradu's full-sized avatar
💭
We were promised flying cars, instead we got 140 characters.

Samson Radu samsonradu

💭
We were promised flying cars, instead we got 140 characters.
View GitHub Profile
@samsonradu
samsonradu / index.js
Last active August 29, 2015 13:56 — forked from mteichtahl/index.js
this.$palettes.on('hidden.bs.collapse', function (e) {
var $this = $(this),
targetPage = $target.attr('id').slice(0, -6),
$target = $(e.target);
var $i = $("span[itemprop=expandCollapseIcons] i", $("#" + targetPage + "-panel");
if ($i.hasClass('icon-chevron-down')) {
$i.removeClass('icon-chevron-down').addClass('icon-chevron-up');
} else {
$i.removeClass('icon-chevron-up').addClass('icon-chevron-down');
@samsonradu
samsonradu / index.js
Last active August 29, 2015 13:56 — forked from mteichtahl/index.js
this.$palettes.on('hidden.bs.collapse', function (e) {
var $this = $(this),
$target = $(e.target);
var $i = $("span[itemprop=expandCollapseIcons] i", $target.closest(".panel"));
if ($i.hasClass('icon-chevron-down')) {
$i.removeClass('icon-chevron-down').addClass('icon-chevron-up');
} else {
$i.removeClass('icon-chevron-up').addClass('icon-chevron-down');
}
@samsonradu
samsonradu / gist:5786092
Last active December 18, 2015 12:58
Vim usefull tips
## multi screens
:split/:vsplit - splits screens
crtl+w & arrows - navigate through windows
ctrl+w & < > ** resize horizontal screen
ctrl+w & + - ** resize vertical screen
Exit and go back to editor:
ctrl+z --> fg
@samsonradu
samsonradu / gist:5952926
Last active December 19, 2015 12:09
Node async flow
console.log('first');
function go(){
console.log('third');
};
//next tick starts with this cb
process.nextTick(go);
//async
setTimeout(function(){
console.log('fourth');
@samsonradu
samsonradu / gist:5953187
Last active December 19, 2015 12:09
TCP demo client/server using streams
/* Server */
var fs = require('fs');
var net = require('net');
var Readable = require('stream').Readable;
var Writable = require('stream').Writable;
var server = net.createServer(function(socket){
socket.setKeepAlive(true);
var stream = fs.createReadStream(__dirname+'/out.txt');
var listenMethods = {listenTo: 'on', listenToOnce: 'once'};
// Inversion-of-control versions of `on` and `once`. Tell *this* object to
// listen to an event in another object ... keeping track of what it's
// listening to.
_.each(listenMethods, function(implementation, method) {
Events[method] = function(obj, name, callback) {
var listeningTo = this._listeningTo || (this._listeningTo = {});
var id = obj._listenId || (obj._listenId = _.uniqueId('l'));
listeningTo[id] = obj;
@samsonradu
samsonradu / gist:7967485
Last active December 31, 2015 09:29
8 Queens problem (recursive)
//check if the position about to be added threatens anyone
function isValid(board, x, y){
for (var i=0; i<board.length; i++){
if (board[i]!=-1){
if (i == x)
return false;
if (board[i] == y)
return false;
if ((i-x == board[i]-y) || (i-x)/(board[i]-y) == 1 || (i-x)/(board[i]-y) == -1)
return false;
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Backbone.js example</title>
<link rel="stylesheet" type="text/css" href="css/sunny/jqueryui.min.css"/>
</head>
<body>
<!-- "slider" is a jquery slider -->
<div id="slider"></div>
@samsonradu
samsonradu / gist:92006d38d6b76cbfa7ef
Last active June 20, 2016 12:09
Browser Console output in a div (for mobile devices without a console view)
function consolify(el){
var oLog = console.log;
var oWarn = console.warn;
var oErr = console.error;
console.log = console.info = function(message){
if (oLog)
oLog.call(console, message);
write(message, el, "info");
};
<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function aes_encrypt($data, $aes_key, $sha_key) {
// apply PKCS#7 padding
$pad = 16-strlen($data)%16;
$data .= str_repeat(chr($pad),$pad);
// generate random IV