Skip to content

Instantly share code, notes, and snippets.

View lutsen's full-sized avatar

Lútsen Stellingwerff lutsen

View GitHub Profile
@lutsen
lutsen / A Google Drive push notifications.md
Last active May 13, 2022 20:22 — forked from magnetikonline/dumprequest.php
How to set up Google Drive push notifications for a file, and test if they work by catching them and writing them in a file with a PHP script.

Activate notifications for the file with ID [file-id] by posting some JSON to this URL: https://www.googleapis.com/drive/v3/files/[file-id]/watch Authorization: Bearer auth_token_for_current_user Content-Type: application/json

Minimal JSON you need to POST:

{
  "id": "[some unique ID for your push, you can define it yourself but it mus be unique]",
 "type": "web_hook",
@lutsen
lutsen / select_element_at_same_position.js
Created March 23, 2017 15:18
Select elements at the same position in a different node with jQuery.
// Use index() to find the position and eq()to select a different element on the same position.
$(this).addClass('active');
$('.collage').eq( $(this).index() ).addClass('active');
@lutsen
lutsen / removedirectory.php
Created April 19, 2015 13:12
Remove a directory and it's contents.
<?php
function removeDir($path) {
// Add trailing slash to $path if one is not there
if (substr($path, -1, 1) != "/") {
$path .= "/";
}
$normal_files = glob($path . "*");
$hidden_files = glob($path . "\.?*");
@lutsen
lutsen / getpath.php
Created April 19, 2015 13:09
Get the absolute path of a file in PHP
<?php echo dirname(__FILE__); ?>
@lutsen
lutsen / ngconfirmclick.js
Last active August 29, 2015 14:14
An Angular directive to show a javascipt confirmation message when the user clicks a page element. The ng-confirm-click attribute contains the text in the confirmation window. The confirmed-click attribute contains the actual ation that is executed if the user confirms.
// http://stackoverflow.com/questions/18313576/confirmation-dialog-on-ng-click-angularjs
// http://plnkr.co/edit/YWr6o2?p=preview
angular.module('yourApp')
.directive('ngConfirmClick', function () {
return {
link: function (scope, element, attr) {
var msg = attr.ngConfirmClick || "Are you sure?";
var clickAction = attr.confirmedClick;
element.bind('click',function (event) {
@lutsen
lutsen / ImageController.js
Created January 20, 2015 09:00
Serving files from Modulus Cloud Storage with Sails
module.exports = {
get: function (req, res) {
res.sendfile( sails.config.uploaddir + req.param('dir') + '/' + req.param('file') );
},
// List the app-storage directory
listdir: function (req, res) {
var fs = require('fs');
return res.json( fs.readdirSync(sails.config.uploaddir) );
@lutsen
lutsen / togglemenu.js
Last active August 29, 2015 14:06
Hide a menu on the top of the page when scrolling down, and show it when scrolling up. Check out the example here: http://codepen.io/anon/pen/dPGggg
var menu_height = 80;
var menu_visible = true;
var old_scroll = $(window).scrollTop();
function checkMenu() {
new_scroll = $(window).scrollTop();
if (old_scroll < new_scroll && new_scroll > 0) {
// Scroll down
if (menu_visible == true) {
toggleMenu();
@lutsen
lutsen / Threaded.php
Last active August 29, 2015 14:04
Make a Threaded multi level array from a two level array with parent id's. For example comments or a page tree. The class returns an array. Original code from http://www.jongales.com/blog/2009/01/27/php-class-for-threaded-comments/
<?php
// From http://www.jongales.com/blog/2009/01/27/php-class-for-threaded-comments/
// This modified code now returns an array.
class Threaded {
public $parents = array();
public $children = array();
@lutsen
lutsen / swapmainimg.js
Created April 13, 2014 11:52
Swap a "main" image by hovering over a thumb image.
// Swap a "main" image by hovering over a thumb image.
// They both need to have the same scr, except for the "template" part.
$(function () {
$( '.thumbimg' ).each( function (i) {
$( this ).on({
mouseenter: function() {
$('#mainimg').attr(
'src',
@lutsen
lutsen / index.html
Created March 11, 2014 14:36
Make X-editable work with List.js in a Booststrap 3 styled table. The problem: X-editable will mess up the table layout when used on a <td> element. But List.js won't work if the table data is in another element inside the <td> element. The solution: create a <span> element every time the editable <td> is clicked, and remove it every time the X-…
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>X-editable and List.js Datagrid</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">