This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
prefix_code.py | |
Copyright 2012-2013 Josiah Carlson | |
Released under the GNU LGPL v 2.1 license | |
This module offers the ability to encode/decode a sequence of integers into | |
strings that can then be used to compare sequences of integers (or paths on | |
trees) quickly. This module was originally intended to be used in a case- | |
preserving index in a relational database (where 'Z' comes before 'a', as is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Exercise 3 | |
*/ | |
def countChange(money: Int, coins: List[Int]): Int = { | |
if (money == 0) 1 | |
else if (money < 0 || coins.isEmpty) 0 | |
else countChange(money, coins.tail) + countChange(money - coins.head, coins) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PostsController < ActionController::Base | |
def create | |
Post.create(post_params) | |
end | |
def update | |
Post.find(params[:id]).update_attributes!(post_params) | |
end | |
private |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELIMITER $$ | |
CREATE PROCEDURE `geodist`(IN mylat float, IN mylon float, IN dist int) | |
BEGIN | |
declare lon1 float; declare lon2 float; | |
declare lat1 float; declare lat2 float; | |
set lon1 = mylon-dist/abs(cos(radians(mylat))*111.1); | |
set lon2 = mylon+dist/abs(cos(radians(mylat))*111.1); | |
set lat1 = mylat-(dist/111.1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def render(template_name, tmpl_vars={}, cache_key=None, | |
cache_type=None, cache_expire=None): | |
globs = pylons_globals() | |
tmpl_vars.update(globs) | |
@contextfunction |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from routes import Mapper | |
class CustomMapper(Mapper): | |
def match(self, url= None, environ= None): | |
if not url and not environ: | |
raise RoutesException('URL or environ must be provided') | |
if not url: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from routes import Mapper | |
class CustomMapper(Mapper): | |
def match(self, url= None, environ= None): | |
if not url and not environ: | |
raise RoutesException('URL or environ must be provided') | |
if not url: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 Query SET NAMES utf8 | |
144 Init DB wordpress | |
144 Query SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes' | |
144 Query SELECT option_value FROM wp_options WHERE option_name = 'sidebars_widgets' LIMIT 1 | |
144 Query SELECT option_value FROM wp_options WHERE option_name = 'rewrite_rules' LIMIT 1 | |
144 Query SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.post_date DESC LIMIT 0, 10 | |
144 Query SELECT FOUND_ROWS() | |
144 Query SELECT t.*, tt.*, tr.object_id FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category', 'post_tag') AND tr.object_id IN (4, 1) ORDER BY t.name ASC | |
144 Query SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (4,1) | |
144 Query SELECT option_value FROM wp_options WHERE option_name = 'kubrick_header_image' LIMIT 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db = ['pri','secondo','terzo','quarto','quinto','sesto'] | |
for string in db: | |
string_ascii= '' | |
s_len = len(string) | |
if (s_len > 5): string = string[:5] | |
for char in string: string_ascii+= str(ord(char)) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Element = { | |
visible: function() {return (!this.hasClassName('toggle'));}, | |
toggle: function() {if (this.visible()) { this.hide();} else {this.show();}}, | |
hide: function() {this.addClassName('toggle'); return this;}, | |
show: function() { this.removeClassName('toggle'); return this;}, | |
remove: function() { this.getParentNode().removeChild(this);return null;}, | |
empty: function() {while (this.getLastChild()) { this.removeChild(this.getLastChild());}} | |
} | |
function $(element) { | |