Skip to content

Instantly share code, notes, and snippets.

@Magentron
Magentron / dpkg-verify.alias.sh
Created August 10, 2016 08:15
An alias to verify that installed files are unchanged using dpkg package's md5sums
dpkg-verify() {
exitcode=0
for file in $*; do
pkg=`dpkg -S "$file" | cut -d: -f 1`
hashfile="/var/lib/dpkg/info/$pkg.md5sums"
if [ -s "$hashfile" ]; then
rfile=`echo "$file" | cut -d/ -f 2-`
phash=`grep -E "$rfile\$" "$hashfile" | cut -d\ -f 1`
hash=`md5sum "$file" | cut -d\ -f 1`
if [ "$hash" = "$phash" ]; then
@pierremoreau
pierremoreau / Command + Output
Created July 30, 2016 16:26
Compiling CUDA kernel which uses `surf2Dwrite()`
% clang++ --cuda-path=/opt/cuda --cuda-gpu-arch=sm_30 -std=c++14 -I/opt/cuda/include surface.cu -o surf -L/opt/cuda/lib64 -lcudart_static -ldl -lrt -pthread
surface.cu:15:3: error: use of undeclared identifier 'surf2Dwrite'
surf2Dwrite(make_float4(0.0f, 0.0f, 0.0f, 1.0f), result_surface, index.x * sizeof(float4), index.y);
^
1 error generated.

GitHub-flavored Markdown does not use C-style escapes for escaping backticks inside spans. Instead, GFM uses double, significant whitespaced, backticks.

Two backticks, then a space, then a backtick, then a space, then two more backticks:

`` ` ``

produces:

@maxtruxa
maxtruxa / Makefile
Last active May 12, 2024 21:49
Generic makefile for C/C++ with automatic dependency generation, support for deep source file hierarchies and custom intermediate directories.
# output binary
BIN := test
# source files
SRCS := \
test.cpp
# files included in the tarball generated by 'make dist' (e.g. add LICENSE file)
DISTFILES := $(BIN)
@victornpb
victornpb / getDeepVal.js
Last active February 22, 2019 14:36
access a object value using a path like getDeepVal(obj, "foo.bar.baz")
/**
* Access a deep value inside an object
* Works by passing a path like "foo.bar", also works with nested arrays like "foo[0][1].baz"
* @author Victor B. https://gist.github.com/victornpb/4c7882c1b9d36292308e
* Unit tests: http://jsfiddle.net/Victornpb/0u1qygrh/
* @param {any} object Any object
* @param {string} path Property path to access e.g.: "foo.bar[0].baz.1.a.b"
* @param {any} [defaultValue=undefined] Optional value to return when property doesn't exist or is undefined
* @return {any}
*/
# create
post '/users' => sub {
my $user = resultset('User')->new_result({});
my $form = SampleApp::Form::User->new;
$form->process(item => $user, params => { params });
if ($form->validated) {
sign_in $user;
deferred success => 'Welcome to the Sample App!';
@ViteFalcon
ViteFalcon / BackgroundImage.cpp
Last active September 9, 2019 07:13
OpenSceneGraph: Creating background image
// create a camera to set up the projection and model view matrices, and the subgraph to draw in the HUD
osg::ref_ptr<osg::Camera> camera = new osg::Camera();
// set the view matrix
camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
// use identity view matrix so that children do not get (view) transformed
camera->setViewMatrix(osg::Matrix::identity());
// set the projection matrix to be of width and height of 1
camera->setProjectionMatrix(osg::Matrix::ortho2D(0, 1.0f, 0, 1.0f));
// set resize policy to fixed
@zed
zed / leapseconds.py
Last active August 15, 2022 11:18
leap seconds
#!/usr/bin/env python
"""Get TAI-UTC difference in seconds for a given time using tzdata.
i.e., find the number of seconds that must be added to UTC to compute
TAI for any timestamp at or after the given time[1].
>>> from datetime import datetime
>>> import leapseconds
>>> leapseconds.dTAI_UTC_from_utc(datetime(2005, 1, 1))
datetime.timedelta(0, 32)
@taichunmin
taichunmin / windows_appkey.md
Last active May 6, 2021 03:13
Windows AppKey

如何修改 Windows 鍵盤對應

現在的 Keyboard 通常會附多媒體鍵,不過預設值打開可能就是討人厭音質又差的 Windows Media Player。 如果我們希望這些鍵可以按下去是開啟我們想要的軟體,此時通常要裝 Driver,問題是有時候會找不到 Driver,那也沒關係,直接改機碼就可以囉,以下是說明:

  1. 先執行 regedit
    • 機碼位於 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\
  2. 在其下加入數字機碼,代表對應的 AppKey 按鍵 (詳見對應表)
    • 例:16 就是 Media 切換功能
    • 要換掉的話可以先將原來的值備份
@paulirish
paulirish / what-forces-layout.md
Last active May 17, 2024 18:01
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent