Skip to content

Instantly share code, notes, and snippets.

View 6temes's full-sized avatar
😏
I have a plan

Daniel 6temes

😏
I have a plan
View GitHub Profile
@6temes
6temes / gist:19e4016305e890ed5e02
Last active August 29, 2015 14:00
Programatically create mouse events with Google Dart
import 'dart:html';
import 'dart:async';
void main() {
// Create the target element.
DivElement menuSprite = new DivElement()
..style.height = "50px"
..style.width = "50px"

Contract Killer

The popular open-source contract for web designers and developers by Stuff & Nonsense

  • Originally published: 23/12/2008
  • Revised date: 15/12/2013
  • Original post

@6temes
6temes / PwQGoo.markdown
Created February 13, 2015 07:57
PwQGoo

The thing that students have the hardest time on when learning functional programming is how to process a recursive structure while maintaining some sort of "state", the result if you will. I'll attempt here to demystify the process.

Functional programming languages almost always use a lot of recursively defined structures. Depending on the language those can be implemented in various ways, but in any case the end result is the same. A structure of this type is either an "atom", i.e. an irreducible thing, or a "compound" consisting of substructures of the same form.

For example a "list" is either an Empty/Nil list (the "atom") or it is formed as a Cons of a value and another list (compound form). That other "sublist" can itself be empty or another cons and so on and so forth. A tree is similar. It is either empty, or it consists of a triple of a value and two sub-trees, left and right.

Almost every problem we encounter is a question about doing something with all entries in a structure. To solve these prob

@6temes
6temes / directives_calendar.js
Last active August 29, 2015 14:23
Minicalendar AngularJS
// Calendar
//
// Note: This calendar uses some ES6 features, so make sure that the code gets transpilled (f.e. with Babel) in the pipelane.
// Also, there are no DI annotations, so it is recommended to use `gulp-ng-annotate` or equivalent.
(function () {
'use strict';
angular
.module('myModule')
@6temes
6temes / slick.scala
Created June 16, 2015 12:33
SLICK 3.0 and Scala PlayFramework 2.4.0 -- Get results from Database.
// Model
case class Thing(id: Option[Int], name: String)
object Thing {
implicit val fmt = Json.format[Thing]
}
class Things(tag: Tag) extends Table[Thing](tag, "thing") {
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
@6temes
6temes / circle.yml
Created May 23, 2016 05:21
Upload result of static analysis tools to GitHub
dependencies:
pre:
- bin/create_github_statuses.sh
test:
post:
- bundle exec rake factory_girl:lint
- bundle exec rubocop --format html -o ${CIRCLE_ARTIFACTS}/rubocop_output.html
- bundle exec brakeman -o ${CIRCLE_ARTIFACTS}/brakeman_output.json -o ${CIRCLE_ARTIFACTS}/brakeman_output.html
- bundle exec rubycritic app lib --mode-ci --path ${CIRCLE_ARTIFACTS}/rubycritic/
@6temes
6temes / text.md
Created December 7, 2016 06:56
The story of ActiveModel

ActiveModel

ActiveModel useful tool that some developers tend to overlook when getting started developing with Rails but that, well used, can add a lot of clarity and convenience to the code in some cases.

The use case of ActiveModel to have a class that behave like an ActiveRecord model, but without DB persistence. That allows, just by importing ActiveModel into a regular Ruby class, to get a lot of useful features that usually belong only to Rails models. These features include validation, serialization, callbacks, attribute methods, etc.

ActiveModel is, somehow, still a bit obscure part of Rails, but the official Rails Guide has some useful examples where we can get a glimpse of how poweful it is.

The story of ActiveModel is interesting as well. Back in 2008 there was an important schism of Rails 2 when Ezra Zygmuntowicz and Yehuda Katz developed [Merb](https://en.wikipedia.org/wiki

@6temes
6temes / .gitconfig
Created December 15, 2016 07:57
Git oops
[alias]
sync = "!git checkout master && git pull origin master && git fetch -p origin \
&& for f in $(git branch --merged | grep -v master | grep -v '*'); do \
git branch -d $f; done"
please = push --force-with-lease
amend = commit --amend --no-edit -a
oops = "!git amend && git please"
@6temes
6temes / fb_sdk.js
Last active October 22, 2019 18:38
Compatibility between Facebook Plugin and Turbolinks 5
// FacebookSDK
// https://developers.facebook.com/docs/plugins/page-plugin/
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.8";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk')); // Replace 'facebook-jssdk' with your page id.