Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Stefano Pirra pste

🎯
Focusing
View GitHub Profile
@pste
pste / vue-expand-datatable.vue
Created Sep 6, 2019
Vuetify 1.5.x expandable datatable (by an external button)
View vue-expand-datatable.vue
<v-btn @click="explodeAll">{{exploded}}</v-btn>
<v-data-table
:headers="headers"
:items="items"
item-key="name"
ref="itemsTable"
expand
>
(..)
@pste
pste / pg-sequence.sql
Created Sep 6, 2019
Playing with PostgreSQL's sequences
View pg-sequence.sql
-- lets play with sequences:
create table items (id serial primary key, name varchar(10));
insert into items(name) values ('foo');
-- manually insert into a serial is allowed BUT it breaks the sequence!
insert into items(id,name) values (2,'foo');
-- now what do you expect?
select currval(pg_get_serial_sequence('items', 'id')); -- ouch! nextval is 1!!
-- ok, let's fix it up!
SELECT setval(pg_get_serial_sequence('items', 'id'), (select max(id)+1 from public.items));
@pste
pste / filesniff.js
Last active Apr 13, 2018
sniffing list-of-files info (node.js)
View filesniff.js
var allstats = filelist.map(filename => ({name: filename, path: path.parse(filename), stats: fs.statSync(filename) }));
@pste
pste / select_latest_version.sql
Last active Sep 7, 2017
Comparison between "the most recent record" approaches
View select_latest_version.sql
SET NOCOUNT ON
SET STATISTICS IO ON
DECLARE @t TABLE (
Id INT IDENTITY(1,1)
, MyValue INT
, MyDate DATE
)
INSERT INTO @t VALUES(1,'2015-01-01')
@pste
pste / node_working_dom_v1.js
Created Aug 31, 2017
Node.js DOM parsing with promises
View node_working_dom_v1.js
var request = require('request');
var jsdom = require('jsdom');
var promise = require('promise');
var colors = require('colors');
var util = require('util');
function get(url) {
return new Promise(function (resolve, reject) {
console.log('>>>'.yellow, 'started', 'get'.cyan, '[', url.yellow, ']');
@pste
pste / fileReadAndZip.cs
Created Aug 23, 2017
Read a file and zip its content in RAM
View fileReadAndZip.cs
FileInfo fi = new FileInfo(fullpath);
String b64ZippedData = String.Empty;
using (FileStream filestream = fi.OpenRead()) // source
{
using (MemoryStream memorystream = new MemoryStream()) // destination
{
using (GZipStream gzipstream = new GZipStream(memorystream, CompressionMode.Compress, false)) // compression engine
{
filestream.CopyTo(gzipstream);
}
View file_post.html
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<head>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
</head>
<body>
<button id="uploadbtn">Click me to upload a file ...</button>
<form id="uploadform" action="sendfile" method="post" enctype="multipart/form-data" style="display:none">
<input id="uploadfile" type="file" name="file1" >
View multi-column-sort.js
var items = [{name:"a", age:22}, { name:"b", age:11}, {name:"a", age: 10}]
var sortingfields = {name:true, age:true} // This is used as a dictionary. Sort by "name" DESC and "age" ASC
// do the items sort
items.sort((a,b) => {
for (col in sortingfields) { // added properties are positional
if (a[col] != b[col]) { // if they are equal, sorting is made on the next column
if (sortingfields[col] === true) return a[col] > b[col] // if ASC === true
else return a[col] < b[col]
}
@pste
pste / handlebars-template.html
Last active Jun 12, 2017
Handlebars template
View handlebars-template.html
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<head>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.10/handlebars.min.js" crossorigin="anonymous"></script>
</head>
<body>
<div id="main">
<script type="text/x-handlebars-template">