Skip to content

Instantly share code, notes, and snippets.

@jmrr
jmrr / mysql2parquet.scala
Last active June 23, 2022 20:04
MySQL tables to parquet files on the Spark shell
val sqlContext = new org.apache.spark.sql.SQLContext(sc) // optional
val df = sqlContext.load("jdbc", Map(
"url" -> "jdbc:mysql://<ip.address.your.db>/<table>?user=<username>&password=<pwd>",
"dbtable" -> "<tablename>"))
df.select("<col1>","<col2>","<col3>").save("</path/to/parquet/file.parquet>","parquet")
//Alternatively, to save all the columns:
@peterc
peterc / strhash.rb
Created August 9, 2014 15:22
strhash.rb
# not for production, obviously
def hash(str, length_of_hash = 20)
added = str.codepoints.map(&:ord).each_slice(length_of_hash).inject do |a, b|
a.map.with_index { |c, d| (c + (b[d] || 0)) % 256 }
end
added.map { |val| val.to_s(16) }.join
end
@xmlking
xmlking / Enum.es6.js
Last active June 25, 2019 18:09
JavaScript Enums with ES6, Type Checking and Immutability
export class EnumSymbol {
sym = Symbol.for(name);
value: number;
description: string;
constructor(name: string, {value, description}) {
if(!Object.is(value, undefined)) this.value = value;
if(description) this.description = description;
@staltz
staltz / introrx.md
Last active July 19, 2026 16:25
The introduction to Reactive Programming you've been missing
@samgiles
samgiles / flatMap.js
Created June 20, 2014 11:32
Javascript flatMap implementation
// [B](f: (A) ⇒ [B]): [B] ; Although the types in the arrays aren't strict (:
Array.prototype.flatMap = function(lambda) {
return Array.prototype.concat.apply([], this.map(lambda));
};
@satyagraha
satyagraha / gist:11172010
Created April 22, 2014 09:37
Gradle-Graphviz 1
task showConfigurations << {
new File("graph/configurations.dot").withWriter { out ->
out.println "digraph configurations {"
out.println "rankdir=BT;"
configurations.all { con ->
out.println "${con.name} [shape=box];"
con.extendsFrom.each { ext ->
out.println "${con.name} -> ${ext.name};"
}
}
@DanHerbert
DanHerbert / fix-homebrew-npm.md
Last active June 29, 2026 14:04
Instructions on how to fix npm if you've installed Node through Homebrew on Mac OS X or Linuxbrew

OBSOLETE

This entire guide is based on an old version of Homebrew/Node and no longer applies. It was only ever intended to fix a specific error message which has since been fixed. I've kept it here for historical purposes, but it should no longer be used. Homebrew maintainers have fixed things and the options mentioned don't exist and won't work.

I still believe it is better to manually install npm separately since having a generic package manager maintain another package manager is a bad idea, but the instructions below don't explain how to do that.

Fixing npm On Mac OS X for Homebrew Users

Installing node through Homebrew can cause problems with npm for globally installed packages. To fix it quickly, use the solution below. An explanation is also included at the end of this document.

@pavelbinar
pavelbinar / gist:6333285
Last active July 27, 2022 07:49
JavaScript: Random Boolean
/* Random Boolean */
var randomNumber = Math.random() >= 0.5;
console.log(randomNumber);
@ara303
ara303 / tumblr-lightbox-for-photos.js
Last active December 5, 2018 10:31
Use Tumblr's built-in lightbox to display high resolution photos. I don't necessarily recommend using this anymore as it unnecessarily relies on jQuery, which you may not need. For a vanilla JS version, see: https://gist.github.com/edadams/5ce1ec3d0b1f69e80724af7eb3b606f4
Hey! Just to let you know there is a much better version of this script that doesn't require jQuery here:
https://gist.github.com/edadams/5ce1ec3d0b1f69e80724af7eb3b606f4
For posterity, and because this Gist got unexpectedly popular for a random code snippet, I will preserve the original below. Please do know that I've figured out a much better way to do this, which is above.
$(function(){ // shorthand document.ready()
$('.make_lightbox').each(function(){ // this is just an element I let them click, it carries a series of data- attributes.
$(this).on('click',function(){ // when clicked. this is the newer jQuery click() handler that's only in v1.8+ so that may be something to note.
var lbArray = []; // create blank array.
var arrayContents = {"width":$(this).data('width'), "height":$(this).data('height'), "low_res":$(this).data("lowres"), "high_res":$(this).data('highres')}; // make set of the data- attributes.
@VitToCode
VitToCode / octave.spec
Created June 11, 2013 21:27
RPM spec for latest Octave (http://www.gnu.org/software/octave/‎) Octave >= 3.6.4
Summary: A high-level language, primarily intended for numerical computations
Name: octave
Version: 3.6.4
Release: 1.el6
#Epoch: 2
License: GPL
Group: Applications/Mathematics
URL: http://www.octave.org
Source0: ftp://ftp.gnu.org/gnu/octave/octave-%{version}.tar.bz2
Source1: octave.png