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 / delete_artifacts.js
Last active February 3, 2023 18:29
Deleting artifacts in GCP's Cloud Storage (ignores latest and leaves at least two versions)
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}`);
@krasimir
krasimir / ReactHooks.js
Created November 11, 2018 04:51
Demoit example
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 April 17, 2014 14:00
Demonstrating Node.js single threadness
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 August 29, 2015 13:58
Extending
var Base = require('./Base');
module.exports = Base.extend({
});
@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;
};
@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 / 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 / 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 / blink.css
Created January 9, 2013 12:23
CSS blink animation
@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;
},