Skip to content

Instantly share code, notes, and snippets.

View bartekupartek's full-sized avatar

Bartłomiej Różański bartekupartek

View GitHub Profile
@onyxfish
onyxfish / example1.py
Created March 5, 2010 16:51
Basic example of using NLTK for name entity extraction.
import nltk
with open('sample.txt', 'r') as f:
sample = f.read()
sentences = nltk.sent_tokenize(sample)
tokenized_sentences = [nltk.word_tokenize(sentence) for sentence in sentences]
tagged_sentences = [nltk.pos_tag(sentence) for sentence in tokenized_sentences]
chunked_sentences = nltk.batch_ne_chunk(tagged_sentences, binary=True)
@runemadsen
runemadsen / description.markdown
Created September 26, 2011 15:23
Reverse polymorphic associations in Rails

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.

@rf-
rf- / validator.rb
Created April 6, 2012 19:57
Demonstrate validation of arbitrary fields (e.g., hstore)
#!/usr/bin/env ruby
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => ':memory:'
)
ActiveRecord::Schema.define do
@CMCDragonkai
CMCDragonkai / angularjs_directive_attribute_explanation.md
Last active November 29, 2023 15:35
JS: AngularJS Directive Attribute Binding Explanation

AngularJS Directive Attribute Binding Explanation

When using directives, you often need to pass parameters to the directive. This can be done in several ways. The first 3 can be used whether scope is true or false. This is still a WIP, so validate for yourself.

  1. Raw Attribute Strings

    <div my-directive="some string" another-param="another string"></div>
@branneman
branneman / better-nodejs-require-paths.md
Last active October 18, 2024 20:29
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@prio
prio / server.ex
Created January 6, 2014 22:16
Elixir gen_server example
defmodule Tcprpc.Server do
use GenServer.Behaviour
defrecord State, port: nil, lsock: nil, request_count: 0
def start_link(port) do
:gen_server.start_link({ :local, :tcprcp }, __MODULE__, port, [])
end
def start_link() do
@omegahm
omegahm / fizzbuzz.ex
Created May 19, 2015 16:23
FizzBuzz in Elixir
defmodule FizzBuzz do
def fizzbuzz(n) do
whichfizz(rem(n, 3), rem(n, 5), n)
end
defp whichfizz(0, 0, _), do: "FizzBuzz"
defp whichfizz(0, _, _), do: "Fizz"
defp whichfizz(_, 0, _), do: "Buzz"
defp whichfizz(_, _, n), do: n
end
@omegahm
omegahm / fizzbuzz.rb
Last active November 9, 2015 13:53
Fizzbuzz in Ruby
class Fiznum
attr_accessor :num
def initialize(num)
self.num = num
end
def fizzbuzz?
num % 15 == 0
end
@pete2786
pete2786 / project_comment.rb
Last active May 30, 2016 08:38
Slack Notifiable and Example
class ProjectComment < ActiveRecord::Base
include SlackNotifiable
belongs_to :user
belongs_to :project
has_one :organization, through: :project
def slack_message
"#{user.name} has commented on #{project.title}: #{description}"
end
@henrik
henrik / poolboy_demo.ex
Last active December 16, 2020 13:56 — forked from sasa1977/poolboy_demo.ex
Example of using Poolboy in Elixir to limit concurrency (e.g. of HTTP requests).
defmodule HttpRequester do
use GenServer
def start_link(_) do
GenServer.start_link(__MODULE__, nil, [])
end
def fetch(server, url) do
# Don't use cast: http://blog.elixirsips.com/2014/07/16/errata-dont-use-cast-in-a-poolboy-transaction/
timeout_ms = 10_000