Skip to content

Instantly share code, notes, and snippets.

View krasimir's full-sized avatar
📝
Writing

Krasimir Tsonev krasimir

📝
Writing
View GitHub Profile
@krasimir
krasimir / ExpressjsDriver.js
Created November 30, 2012 20:15
Organization of Expressjs type of node apps
var mode = process.argv[2] ? process.argv[2] : "local";
mode = mode.replace("/", "") == "tests" ? "local" : mode;
var express = require('express');
var app = express();
var config = require("./config/" + mode).config;
var glob = require("glob");
var path = require('path');
// helper middlewares
@krasimir
krasimir / GetYourGitHubActiviti.js
Last active December 10, 2015 06:08
Get your latest GitHub activity with JavaScript (requires jQuery)
var GitHub = (function() {
var feed = function(user, callback) {
var url = "https://api.github.com/users/" + user + "/events";
$.ajax({
url: url,
dataType: 'jsonp',
success: function(results) {
callback(null, results);
},
@krasimir
krasimir / GetYourLatestFacebookActivities.php
Last active December 10, 2015 07:38
Get your latest Facebook activities.
<?php
class FacebookFeed {
private $appID;
private $appSecret;
private $fbID;
private $appToken;
public function __construct($appID, $appSecret, $fbID, $appToken = false) {
@krasimir
krasimir / GetYourLatestTweets.js
Last active December 10, 2015 08:18
Get your latest Twitter activity
var Twitter = (function() {
var feed = function(userId, callback, count) {
var url = "https://api.twitter.com/1/statuses/user_timeline.json?screen_name=" + userId + "&count=" + (count || 10);
$.ajax({
url: url,
dataType: 'jsonp',
success: function(results) {
callback(null, results);
},
@krasimir
krasimir / Element.js
Last active December 10, 2015 19:38
A Backbone.JS style object for creating JavaScript applications. It's purpose is to hold the business logic too. Dependencies: jQuery, underscore
var element = {
el: $("<div></div>"),
appended: [],
listeners: {},
init: function() {
return this;
},
onAppend: function() {
return this;
},
@krasimir
krasimir / blink.css
Created January 9, 2013 12:23
CSS blink animation
@krasimir
krasimir / fixPreTags.php
Last active December 12, 2015 02:18
The function removes <br /> tags inside <pre> tags and also make possible writing html.
private function fixPreTags($str) {
$parts = explode('<pre>', $str);
$newStr = '';
if(count($parts) > 1) {
foreach ($parts as $p) {
$parts2 = explode('</pre>', $p);
if(count($parts2) > 1) {
$code = str_replace('<br />', '', $parts2[0]);
$code = str_replace('<br/>', '', $code);
$code = str_replace('<br>', '', $code);
@krasimir
krasimir / ChangePSDFonts.js
Created February 20, 2013 22:29
Change the fonts in your psd automatically.
var console = {log: function(o) { $.writeln(o); }}
var Action = {
applyAction: function(o, layerKind, callback) {
if(o.typename == "LayerSet") {
var layers = o.layers;
for(var i=0; i<layers.length; i++) {
this.applyAction(layers[i], layerKind, callback)
}
} else {
@krasimir
krasimir / Dispatcher.js
Created November 27, 2013 08:05
A simple class for managing events.
var Dispatcher = function(componentName) {
var listeners = [];
return {
on: function(eventName, callback) {
if(!listeners[eventName]) {
listeners[eventName] = [];
}
listeners[eventName].push(callback);
return this;
},
@krasimir
krasimir / YouTube2Iframe.js
Created February 3, 2014 18:53
Convert YouTube link to an iframe
var filterTextArea = function(text) {
text = text.replace(/(<([^>]+)>)/ig, '');
var re = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?([\w\-]{10,12})(?:&feature)?(?:[\w\-]{0})?/g;
var iframe = '<iframe width="640" height="360" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>';
text = iframe.replace('$1', text.split(re)[1]);
return text;
};