Skip to content

Instantly share code, notes, and snippets.

@bernardo-cs
bernardo-cs / karma.rake
Created November 30, 2015 12:12
Rake task build application.js assets
require 'sprockets'
require 'pry'
require 'fileutils'
namespace :karma do
task :start => :environment do
with_tmp_config :start
end
task :run => :environment do
@bernardo-cs
bernardo-cs / gist:b88cac3895d2a1ffe690
Last active January 29, 2016 07:46
simplified collections with duck typing
namespace :assets do
desc "fetch descriptions for youtube videos without descriptions"
task yt_fetch_description: :environment do
BsuDescriptionUpdater.new(YtChanReg, FbPgeReg, IgUsrReg).update_all
end
end
class BsuDescriptionUpdater
def initialize(*source_klasses)
@source_klasses = source_klasses.map { |src| DescriptionUpdater.new(src) }
var API = function () {
};
API.prototype.login = function(username, password) {
console.log("request username and pw to server...");
this.auth_token = "nhonhonho";
};
API.prototype.getUserById = function(user_id) {
if (this.auth_token){
TAGS_TMP_FOLDER="/tmp/tmp_tags"
coffeetags -R -f $TAGS_TMP_FOLDER
ctags -R --languages=ruby --exclude=.git --exclude=log -a -f $TAGS_TMP_FOLDER . $(bundle list --paths)
mv $TAGS_TMP_FOLDER tags
var xhr_request = function (post_url, xsrf_token, ids, start_interval, end_interval, callback){
var request = { page_ids: ids, start: start_interval, end: end_interval};
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", callback);
oReq.open("POST", post_url);
oReq.setRequestHeader("Content-Type", "application/json");
oReq.setRequestHeader("X-CSRF-Token", xsrf_token);
oReq.send(JSON.stringify(request));
};
// ==UserScript==
// @name Verify fitness hut class availability
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.myhut.pt/myhut/aulas/*
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
@bernardo-cs
bernardo-cs / scroll_bulletin_int_view.component.ts
Created September 11, 2017 13:10
Angular 2 directive scrolls into view
import { AfterViewInit, Directive, ElementRef, Input, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Subscription } from 'rxjs/Subscription';
@Directive({
selector: '[flScrollBulletinIntoView]'
})
export class ScrollBulletinIntoViewDirective implements AfterViewInit, OnDestroy {
@Input() bulletinId: number;
private scrollIntoView$: Subscription;
@bernardo-cs
bernardo-cs / editable.directive.ts
Last active September 11, 2017 13:18
Angular 2 direct, make content editable only for admins
import { AfterViewInit, Directive, ElementRef, HostListener, Input } from '@angular/core';
import { UserService } from '../shared/services/user.service';
@Directive({
selector: '[flEditable]'
})
export class EditableDirective implements AfterViewInit {
@Input('endpoint') endpoint;
@bernardo-cs
bernardo-cs / dom_check.js
Last active September 21, 2017 09:15
Verify dom changes every second, reload after 1 minute, send notification if change happened with Tampermonkey and RxJS
// ==UserScript==
// @name Verify fitness hut class availability
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.myhut.pt/myhut/aulas/*
// @grant none
// @require https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.4.3/Rx.js
// ==/UserScript==
@bernardo-cs
bernardo-cs / remove_ifs.js
Created October 9, 2017 10:04
how to remove ifs from js (angular.js) and use filters/reduce
var ids = [];
if ($scope.attendeesToggle) { ids = ids.concat($scope.eventAttendees); }
if ($scope.waitingListToggle) { ids = ids.concat($scope.eventWaitingList); }
//--------
[
{ condition: () => $scope.attendeesToggle, array: $scope.eventAttendees },
{ condition: () => $scope.waitingListToggle, array: $scope.eventWaitingList }