Skip to content

Instantly share code, notes, and snippets.

Avatar
📝
Writing

Krasimir Tsonev krasimir

📝
Writing
View GitHub Profile
@krasimir
krasimir / delete_artifacts.js
Last active Sep 17, 2021
Deleting artifacts in GCP's Cloud Storage (ignores latest and leaves at least two versions)
View delete_artifacts.js
const spawn = require("child_process").spawn;
const KEEP_AT_LEAST = 2;
const CONTAINER_REGISTRIES = [
"gcr.io/<your project name>",
"eu.gcr.io/<your project name>/gcf/europe-west3"
];
async function go(registry) {
console.log(`> ${registry}`);
View ReactHooks.js
const useState = React.useState;
const App = function () {
const [ count, change ] = useState(0);
console.log(`count is: ${ count }`);
return (
<section>
<h1>Counter: { count }</h1>
<button onClick={ () => change(count + 1) }>
Click me
@krasimir
krasimir / server.js
Created Apr 17, 2014
Demonstrating Node.js single threadness
View server.js
var http = require('http');
var getTime = function() {
var d = new Date();
return d.getHours() + ':' + d.getMinutes() + ':' +
d.getSeconds() + ':' + d.getMilliseconds();
}
var respond = function(res, str) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(str + '\n');
console.log(str + ' ' + getTime());
@krasimir
krasimir / A.js
Last active Aug 29, 2015
Extending
View A.js
var Base = require('./Base');
module.exports = Base.extend({
});
@krasimir
krasimir / YouTube2Iframe.js
Created Feb 3, 2014
Convert YouTube link to an iframe
View YouTube2Iframe.js
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;
};
@krasimir
krasimir / Dispatcher.js
Created Nov 27, 2013
A simple class for managing events.
View Dispatcher.js
var Dispatcher = function(componentName) {
var listeners = [];
return {
on: function(eventName, callback) {
if(!listeners[eventName]) {
listeners[eventName] = [];
}
listeners[eventName].push(callback);
return this;
},
@krasimir
krasimir / ChangePSDFonts.js
Created Feb 20, 2013
Change the fonts in your psd automatically.
View ChangePSDFonts.js
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 / fixPreTags.php
Last active Dec 12, 2015
The function removes <br /> tags inside <pre> tags and also make possible writing html.
View fixPreTags.php
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 / blink.css
Created Jan 9, 2013
CSS blink animation
View blink.css
@krasimir
krasimir / Element.js
Last active Dec 10, 2015
A Backbone.JS style object for creating JavaScript applications. It's purpose is to hold the business logic too. Dependencies: jQuery, underscore
View Element.js
var element = {
el: $("<div></div>"),
appended: [],
listeners: {},
init: function() {
return this;
},
onAppend: function() {
return this;
},