This file contains 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
function getRandomMySQLRows($table, $rows, $fields = "*"){ | |
// $table = MySQL table | |
// $rows = number of rows to randomly select | |
// $fields = fields to select separated by a comma | |
// returns a string with the SQL that needs to be preformed | |
if($rows == 0){ return ""; }; | |
$result = mysql_query("SELECT MAX(id) FROM $table WHERE 1"); | |
$count = mysql_result($result,0,0); |
This file contains 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
module QualificationMask | |
def bitmask_field_for(field, options) | |
array = options.delete(:with).to_s | |
field = field.to_s | |
methods = field.gsub /_mask/, '' | |
class_eval %( | |
def #{methods}=(#{methods}) | |
#{methods} = [#{methods}] if not #{methods}.is_a?(Array) | |
self.#{field} = (#{methods} & #{array}).map { |r| 2**#{array}.index(r) }.sum |
This file contains 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
#!/bin/bash | |
ENV='staging' | |
BRANCH='master' | |
GOT=`git status` | |
EXPECTED="# On branch master | |
nothing to commit (working directory clean)" | |
if [ "$GOT" != "$EXPECTED" ] |
This file contains 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
module ControllerFormAttributes | |
@@types = {} | |
# form_params_accessors(:user, :email, :password, :password_confirmation) | |
def form_params_accessors(type, attributes) | |
@@types[type] = attributes | |
end | |
# user.update_attributes(form_params_for(:user)) | |
def form_params_for(type) |
This file contains 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
# iPad | |
import console | |
console.clear() | |
# Program | |
def maxSub(a, b): | |
table = {} | |
# Base cases, Empty strings | |
for i in range(0, len(a) + 1): |
This file contains 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
import pgp | |
print("Generating keys...") | |
p = pgp.generateLargePrime(1024) | |
q = pgp.generateLargePrime(1024) | |
mod = p * q | |
print("Generating public key...") | |
public = pgp.generatePublic(p, q) | |
print("Generating private key...") | |
private = pgp.generatePrivate(p, q, public) |
This file contains 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 crypt(mod, key, data, hashes = 50): | |
encrypted = [] | |
for v in data: | |
for i in range(0, hashes + 1): | |
v = (v ** key) % mod | |
encrypted.append(v) | |
return list(map(int, encrypted)) | |
# My keys (p and q are intermediates) | |
p = 11 |
This file contains 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
$ erl | |
1> c(misc_lib). % compile module | |
{ok,misc_lib} | |
2> misc_lib:quickSort([1, 9, 6, 3, 0, 5, 2, 5082, 5, 2]). | |
[0,1,2,2,3,5,5,6,9,5082] |
This file contains 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
int[] rgb = {0,0,0}; | |
int i = 0; // current working index | |
int step = 25; | |
while(true) { | |
// so raise R, raise G, drop R, raise B, drop G, etc? | |
int p = (i + 2) % 3; // previous index | |
if(rgb[i] >= 255 && rgb[p] > 0) { | |
rgb[p] -= step; | |
if(rgb[p] < 0) rgb[p] = 0; |
This file contains 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
public class AnExample { | |
public static void main(String[] args) { | |
System.out.println( | |
ColoredString.s("Such ANSI, Easy Color. Many wow.").bold().cyan().blink(); | |
); | |
} | |
} |
OlderNewer