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
package main | |
import "fmt" | |
import "time" | |
import "encoding/hex" | |
import "hash/fnv" | |
func main() { | |
h := fnv.New64a() |
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 moderate_plus_vigorous_durations_adjusted(start_date=(1.week.ago.beginning_of_day), end_date=(DateTime.now)) | |
query_args = [{value: self.id}, {value: start_date}, {value: end_date}] | |
sql = %Q[ | |
WITH my_vars(intensity_2_duration, intensity_3_duration) AS (VALUES | |
( | |
(SELECT SUM(duration) as intensity_2_duration | |
FROM users | |
INNER JOIN workouts | |
ON workouts.user_id = users.id | |
WHERE |
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
WITH my_vars(intensity_2_duration, intensity_3_duration) AS (VALUES | |
( | |
(SELECT (SUM(duration)*2) FROM users INNER JOIN workouts ON workouts.user_id = users.id | |
WHERE intensity = 3 AND workouts.deleted_at IS NULL), | |
(SELECT SUM(duration) FROM users INNER JOIN workouts ON workouts.user_id = users.id | |
WHERE intensity = 2 AND workouts.deleted_at IS NULL) | |
) | |
) | |
SELECT MAX(date), (SELECT (intensity_2_duration + intensity_3_duration) FROM my_vars) as total_duration, SUM(duration) | |
FROM workouts |
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
upstream unicorn { | |
# fail_timeout=0 means we always retry an upstream even if it failed | |
# to return a good HTTP response (in case the Unicorn master nukes a | |
# single worker for timing out). | |
# for UNIX domain socket setups: | |
server unix:/tmp/unicorn.examplesitehere.sock fail_timeout=0; | |
} | |
server { | |
listen 80; |
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 urllib | |
import urllib.request | |
def DownloadClass(): | |
url = "http://cmes.uccs.edu/Fall2011/Math215/Videos/" | |
ext = ".mov" | |
movie_name = "Math215Lecture" | |
for i in range(1, 27): |
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
+[ Increment ptr(0) and enter loop | |
>++++++++++ Increment byte at ptr(1) 10 times | |
[ While ptr | |
>+++++++ incremement ptr(2) 7 times | |
>++++++++++ increment ptr(3) 10 times | |
>+ increment ptr(4) 1 time | |
>+++ increment ptr(5) 3 times | |
<<<< - back down to ptr 1 and decrement ptr 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
-- | |
-- Person's unoptimized query | |
-- | |
QUERY PLAN | |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
Seq Scan on keyword_tracked_tweets (cost=0.06..484854.06 rows=50015 width=172) (actual time=16639.692..32543.957 rows=1 loops=1) | |
Filter: ((id)::double precision = trunc((random() * ($1)::double precision))) | |
InitPlan 2 (returns $1) | |
-> Result (cost=0.05..0.06 rows=1 width=0) (actual time=0.045..0.047 rows=1 loops=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
# include <stdio.h> | |
int main() { | |
char str[] = "Reverse me!"; | |
int length; | |
for (length = 0; str[length] != '\0'; length++) { |
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
class Ability | |
include CanCan::Ability | |
def initialize(user) | |
user ||= User.new # IE: Guest user isn't signed in, create a user | |
if user.try(:is?, :admin) | |
can :manage, :all | |
elsif !user.roles.empty? && user.approved? | |
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
# m h dom mon dow user command | |
45 5 * * * postgres pg_dumpall -l YOURDBNAME | gzip -c | ssh backup@MYBACKUPSERVER "cat | gzip /YOURDIRECTORYPATH/pg_backups/$(date +\"%Y-%m-%d:%T\")YOURFILENAME.gz" |
NewerOlder