Skip to content

Instantly share code, notes, and snippets.

View ZaninAndrea's full-sized avatar
👨‍💻

Zanin Andrea ZaninAndrea

👨‍💻
View GitHub Profile
LABELS=(
{
'attributes': {
'type': 'rect',
'class':'rect'
},
'inserter': 'sloth.items.RectItemInserter',
'item': 'sloth.items.RectItem',
'hotkey': 'r',
'text': 'Rectangle',
@ZaninAndrea
ZaninAndrea / setup.sh
Created July 19, 2017 13:44
setup new pc
git clone --bare git@github.com:ZaninAndrea/config.git $HOME/.cfg
function config {
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME $@
}
mkdir -p .config-backup
config checkout
if [ $? = 0 ]; then
echo "Checked out config.";
else
echo "Backing up pre-existing dot files.";
@ZaninAndrea
ZaninAndrea / data-mining.js
Last active August 15, 2017 20:54
[Facebook-like link preview] provides facebook-like preview for links #electron #node #js
const request = require("request")
const cheerio = require("cheerio")
const url = "http://foo.bar"
const findTitleInDom = ($dom) => {
return $dom.find("meta[property='og:title']").attr("content") ||
$dom.find("title").text() ||
$dom.find("meta[name=title]").attr("content");
}
@ZaninAndrea
ZaninAndrea / package.json
Created October 7, 2017 19:48
package.json
{
"repository": "https://github.com/UserName/RepoName",
"scripts": {
"build": "build --win",
"ship": "build --win -p always"
}
}
@ZaninAndrea
ZaninAndrea / electron.js
Last active October 7, 2017 19:56
Autoupdate electron
const {app, BrowserWindow, ipcMain} = require('electron');
const {autoUpdater} = require("electron-updater");
let win; // this will store the window object
// creates the default window
function createDefaultWindow() {
win = new BrowserWindow({width: 900, height: 680});
win.loadURL(`file://${__dirname}/index.html`);
win.on('closed', () => app.quit());
return win;
<html>
<head>
<title>Electron AutoUpdater</title>
</head>
<body>
<script>
const ipcRenderer = require('electron').ipcRenderer;
const fuzzyScore = (input, correct) => {
let score = 0
let lastId = 0
for(id in input) {
while(input[id] !== correct[lastId] && lastId < correct.length){
lastId++
score++
}
lastId++
@ZaninAndrea
ZaninAndrea / server.js
Created October 29, 2017 19:04
server.js
const mongodb = require('mongodb'); // load mongodb
const uri = process.env.URI;
@ZaninAndrea
ZaninAndrea / .env
Created October 29, 2017 19:10
.env
URI=mongodb://admin:PASSWORD@ds111885.mlab.com:11885/medium
@ZaninAndrea
ZaninAndrea / server.js
Created November 1, 2017 15:37
server
// init project
const express = require('express'); // the library we will use to handle requests
const app = express(); // instantiate express
app.use(require("cors")()) // allow Cross-domain requests
// base route
app.get("/", function (request, response) {
response.send("TODO") // always responds with the string "TODO"
});